摘要:
双指针:Left和Right,将左指针的零与右指针的非零数交换,且非零数的相对顺序并未改变。 1 def movezeros(nums): 2 n = len(nums) 3 left = right =0 4 while right<n: 5 if nums[right] != 0: 6 nums 阅读全文
摘要:
1 def hIndex(citations): 2 citations.sort() 3 n = len(citations) 4 index = 0 5 while index < n: 6 if n - index <= citations[index]: 7 break 8 index += 阅读全文
摘要:
方法1:原地修改数组 1 ans = [] 2 for num in nums: 3 if nums[abs(num) - 1] < 0: 4 ans.append(abs(num)) 5 nums[abs(num) - 1] *= - 1 6 return ans 方法2:添加偏置量 1 res 阅读全文
摘要:
方法1: 1 counter = set(nums) 2 N = len(nums) 3 res = [] 4 for i in range(1,N+1): 5 if i not in counter: 6 res.append(i) 7 return res 方法2:原地修改数组(这个想法有些厉害 阅读全文