Пример #1
0
    def is_palindrome(self, l):
        ol = l
        nl = linklistnode(l.data)
        l = l.next
        while l:
            nl.insert(l.data)
            l = l.next
        print("reverse")
        nl.print_list()

        while ol:
            if ol.data != nl.data:
                return False
            ol = ol.next
            nl = nl.next
        return True
Пример #2
0
        l = l.next
        while l:
            nl.insert(l.data)
            l = l.next
        print("reverse")
        nl.print_list()

        while ol:
            if ol.data != nl.data:
                return False
            ol = ol.next
            nl = nl.next
        return True
    
if __name__ == "__main__":
    l = linklistnode(3)
    for i in [5,6,3,7,9,5,6,5,6,3]:
        l.append(i)
    l.print_list()
    
    helper = linklistutils()
    helper.rm_dup(l)
    l.print_list()

    test(helper.find_kth_end(l, 100), None)
    test(helper.find_kth_end(l, 1), 6)
    test(helper.find_kth_end(l, 2), 9)
    test(helper.find_kth_end(l, 3), 7)

    pl = linklistnode('r')
    for i in ['a', 'c', 'e', 'c', 'a','r']: