def main(): from utils import build_singly_linked_list, print_singly_linked_list head = build_singly_linked_list([1,2,6,3,4,5,6,]) print_singly_linked_list(head) result = Solution().removeElements(head, 6) print_singly_linked_list(result)
def main(): import sys from os.path import join, abspath sys.path.append(join('..', 'common')) from utils import build_singly_linked_list, print_singly_linked_list head = build_singly_linked_list([5,4,3,2,1]) print_singly_linked_list(head) result = Solution().sortList(head) print_singly_linked_list(result)
def main(): import sys from os.path import join, abspath sys.path.append(join('..', 'common')) from utils import build_singly_linked_list, print_singly_linked_list head = build_singly_linked_list([1,4,3,2,5,2]) x = 3 result = Solution().partition(head, x) print_singly_linked_list(result)
def main(): from utils import build_singly_linked_list, print_singly_linked_list head = build_singly_linked_list([1, 2, 3, 4]) head = build_singly_linked_list([1, 2, 3, 2, 1]) head = build_singly_linked_list([1, 2, 2, 1]) head = build_singly_linked_list([1]) head = build_singly_linked_list([1, 1]) #head = build_singly_linked_list([2, 2, 1, 1, 2, 2]) print_singly_linked_list(head) result = Solution().isPalindrome(head) print result
def main(): import sys from os.path import join, abspath sys.path.append(join('..', 'common')) from utils import build_singly_linked_list, print_singly_linked_list inputs = [None, build_singly_linked_list([1,]), build_singly_linked_list([1,2,3]), build_singly_linked_list([1,2,3,4]), ] for head in inputs: result = Solution().swapPairs(head) print_singly_linked_list(result)
def main(): import sys from os.path import join, abspath sys.path.append(join('..', 'common')) from utils import build_singly_linked_list, print_singly_linked_list head = build_singly_linked_list([1,2,3,4,5]) print_singly_linked_list(head) inputs = [(2,4), (1,2), (2,2)] for m, n in inputs: head = build_singly_linked_list([1,2,3,4,5]) result = Solution().reverseBetween(head, m, n) print 'm, n:', m, n print_singly_linked_list(result)
def main(): import sys from os.path import join, abspath sys.path.append(join('..', 'common')) from utils import build_singly_linked_list, print_singly_linked_list result = Solution().oddEvenList(None) head = build_singly_linked_list([1,2,3,4,5]) result = Solution().oddEvenList(head) print_singly_linked_list(result) head = build_singly_linked_list([1,2,3,4,5,6]) result = Solution().oddEvenList(head) print_singly_linked_list(result)
def main(): import sys from os.path import join, abspath sys.path.append(join('..', 'common')) from utils import build_singly_linked_list, print_singly_linked_list l1 = build_singly_linked_list([2,4,3]) l2 = build_singly_linked_list([5,6,4]) result = Solution().addTwoNumbers(l1, l2) print_singly_linked_list(result) l1 = build_singly_linked_list([5]) l2 = build_singly_linked_list([5]) result = Solution().addTwoNumbers(l1, l2) print_singly_linked_list(result)
def main(): from utils import build_singly_linked_list, print_singly_linked_list head = build_singly_linked_list([1, 2, 3, 4, 5]) print_singly_linked_list(head) result = Solution().removeNthFromEnd(head, 2) print_singly_linked_list(result) head = build_singly_linked_list([1, 2, 3, 4, 5]) result = Solution().removeNthFromEnd(head, 1) print_singly_linked_list(result) head = build_singly_linked_list([1, 2, 3, 4, 5]) result = Solution().removeNthFromEnd(head, 5) print_singly_linked_list(result)
def main(): import sys from os.path import join, abspath sys.path.append(join('..', 'common')) from utils import build_singly_linked_list, print_singly_linked_list head = build_singly_linked_list([1,2,3,4,5]) k = 2 print_singly_linked_list(head) result = Solution().rotateRight(head, k) print_singly_linked_list(result) head = build_singly_linked_list([1,2]) k = 3 print_singly_linked_list(head) result = Solution().rotateRight(head, k) print_singly_linked_list(result)
def main(): import sys from os.path import join, abspath sys.path.append(join('..', 'common')) from utils import build_singly_linked_list, print_singly_linked_list head = build_singly_linked_list([1,2,3,4]) print_singly_linked_list(head) Solution().reorderList(head) print_singly_linked_list(head) Solution().reorderList(None) head = build_singly_linked_list([1,2,3,4,5]) print_singly_linked_list(head) Solution().reorderList(head) print_singly_linked_list(head)
def main(): from utils import build_singly_linked_list, print_singly_linked_list headA = build_singly_linked_list([11, 12]) headB = build_singly_linked_list([21, 22, 23]) headC = build_singly_linked_list([31, 32, 33]) tail = headA while tail.next: tail = tail.next tail.next = headC tail = headB while tail.next: tail = tail.next tail.next = headC print_singly_linked_list(headA) print_singly_linked_list(headB) result = Solution().getIntersectionNode(headA, headB) print_singly_linked_list(result)
def main(): import sys from os.path import join, abspath sys.path.append(join('..', 'common')) from utils import build_singly_linked_list, print_singly_linked_list head = build_singly_linked_list([1,2,3,3,4,4,5]) print_singly_linked_list(head) result = Solution().deleteDuplicates(head) print_singly_linked_list(result) head = build_singly_linked_list([1,1,1,2,3]) print_singly_linked_list(head) result = Solution().deleteDuplicates(head) print_singly_linked_list(result) head = build_singly_linked_list([0,0,0,0,0]) print_singly_linked_list(head) result = Solution().deleteDuplicates(head) print_singly_linked_list(result)