Fruits into Baskets (medium) No-repeat Substring (hard) Longest Substring with Same Letters after Replacement (hard) Longest Subarray with Ones after Replacement (hard) 2. Pattern: two points, 双指针类型 双指针是这样的模式:两个指针朝着左右方向移动(双指针分为同向双指针和异向双指针),直到他们有...
// Solution 1: Keep the statistics of number of nodes for every node in the tree. If you need statistics of a data structure which changes quite often, don't try to bind them together too tight. Use things like timestamps to check if the results in cache needs updating. It's a cac...
Repeat Longest Common Prefix Feb 28, 2020 luogu 洛谷P1605 迷宫 Jan 21, 2021 sql Daily Leads and Partners Jul 18, 2022 01Matrix.go 01 Matrix Sep 27, 2022 01Matrix.java 01 Matrix Apr 15, 2020 3SumClosest.go 3Sum Closest Jul 10, 2023 ...
public int findRepeatNumber(int[] nums) { Set<Integer> dic = new HashSet<>(); for(int num : nums) { if(dic.contains(num)) return num; dic.add(num); } return -1; } } 作者:jyd 链接:https://leetcode.cn/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof/solution/mian-shi-ti-03...
classSolution:deffindRepeatNumber(self, nums: List[int]) ->int: n=len(nums)foriinrange(n):whilenums[i] !=i:ifnums[i] ==nums[nums[i]]:returnnums[i] nums[nums[i]], nums[i]=nums[i], nums[nums[i]]returnFalse 面试题04. 二维数组中的查找 ...
2182.Construct-String-With-Repeat-Limit (M+) 2193.Minimum-Number-of-Moves-to-Make-Palindrome (H+) 2216.Minimum-Deletions-to-Make-Array-Beautiful (M+) 2242.Maximum-Score-of-a-Node-Sequence (M+) 2257.Count-Unguarded-Cells-in-the-Grid (M+) 2275.Largest-Combination-With-Bitwise-AND-Greater...
A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include ...
class Solution { fun climbStairs(n: Int): Int { // 前面第二个数 var lastTwo = 0 // 前一个数 var lastOne = 1 repeat(n) { lastOne += lastTwo lastTwo = lastOne - lastTwo } return lastOne } } 对于每一个题目,不要仅仅满足于通过。最好是不断地优化代码,使得其时间复杂度和空间复...
这里是剑指offer的一些笔记,有几道困难题没做,以后会不上,题解是按照做题序号来的。 数组中重复的数字 新建一个标记数组记录每个数字出现的次数。 暴力搜索 class Solution:deffindRepeatNumber(self,nums:List[int])->int:flags=[0]*len(nums)fori inrange(len(nums)):flags[nums[i]]+=1fori inrange(le...
class Solution { public int findRepeatNumber(int[] nums) { int i = 0; while(i < nums.length) { //当前元素正好在其所对应的位置上 if(nums[i] == i) { i++; continue; } //当前元素所对应的位置的值和当前元素相同,找到重复元素。 if(nums[nums[i]] == nums[i]) return nums[i]; ...