LeetCode - 75. Sort Colors 75. Sort Colors两个易错点: 1.什么时候p才可以+1?当前位置为1 2.nums[p]==2需要提前:换过来的数字可能为0或1,而nums[p]==0换过来的数字只可能是1class Solution:def sortColors(self, nums: List[int]) -> None:...
19. 删除链表的倒数第 N 个结点middle 【链表】 一眼丁真,鉴定为【双指针】 // 执行用时:88 ms, 在所有 TypeScript 提交中击败了6.19%的用户// 内存消耗:43.9 MB, 在所有 TypeScript 提交中击败了51.58%的用户/*** Definition for singly-linked list.* class ListNode {* val: number* next: ListNode...
public static List<Boolean> kidsWithCandies(int[] candies, int extraCandies) { int maxCandies = 0; // 找到当前糖果数量的最大值 for (int candy : candies) { if (candy > maxCandies) { maxCandies = candy; } } List<Boolean> result = new ArrayList<>(); // 判断每个孩子在得到额外糖果后...
Given a start IP addressipand a number of ips we need to covern, return a representation of the range as a list (of smallest possible length) of CIDR blocks. A CIDR block is a string consisting of an IP, followed by a slash, and then the prefix length. For example: "123.45.67.89/...
Repository files navigation README Blind75-Leetcode This repository is purely dedicated to stacking my Blind Leetcode 75 question's solutions , a list of 75 most frequent asked leetcode questions which had helped many developers clear interviews of Google, Amazon, Microsoft, Facebook etc.About...
New Year Gift to every fellow time-constrained engineer out there looking for a job, here's a list of the best LeetCode questions that teach you core concepts and techniques for each category/type of problems! Many other LeetCode questions are a mash of the techniques from these individual ...
class Solution(object): def sortColors(self, nums): """ :type nums: List[int] :rtype: None Do not return anything, modify nums in-place instead. """ n = len(nums) p0 = 0 p2 = n-1 i = 0 while i <= p2: while i <= p2 and nums[i] == 2: nums[i], nums[p2] = num...
leetcode 751. IP to CIDR Given a start IP address ip and a number of ips we need to cover n, return a representation of the range as a list (of smallest possible length) of CIDR blocks. A CIDR block is a string consisting of an IP, followed by a slash, and then the prefix ...
defsortColors(self, nums: List[int])->None: """ Do not return anything, modify nums in-place instead. """ l, r =0, len(nums)-1 i =0 whilei < len(nums): ifi > r: break # 如果遇到0,则和左边交换 ifnums[i] ==0:
classSolution:deffindMin(self,nums:List[int])->int:iflen(nums)<=2:# 最小值出口2returnmin(nums)mid=(len(nums)-1)// 2 # 计算中间的坐标ifnums[mid-1]<nums[mid]<nums[mid+1]:returnmin(self.findMin(nums[:mid]),self.findMin(nums[mid+1:]))# 分治求解else:returnmin(nums[mid-1],...