题目: Sort a linked list in O(n log n) time using constant space complexity. 代码:oj 测试通过 Runtime: 372 ms # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: # @param head, a L
题目: Sort a linked list using insertion sort. 代码:oj测试通过 Runtime: 860 ms # Definition for singly-linked list. # class ListNode: # def __init__(self, x): # self.val = x # self.next = None class Solution: # @param head, a ListNode # @return a ListNode de
题目: Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers 0, 1, and 2 to represent the color red, white, an
链表的归并排序 超时的代码 class Solution: def merge(self, head1, head2): if head1 == None: return head2 if head2 == None: return head1 # head1 and head2 point to the same link list if head1 == head2: return head1 head = None tail = None # the small pointer point
一:Numpy # 数组和列表的效率问题,谁优谁劣 # 1.循环遍历 import numpy as np import time my_arr = np.arange(1000000) my_list = list(range(1000000)) def arr_time(array): s = time.time() for _ in array: _ * 2 e = time.time() return e - s def list_time(list): s = time.time()