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, 双指针类型 双指针是这样的模式:两个指针朝着左右方向移动(双指针分为同向双指针和异向双指针),直到他们有...
classSolution:deffindRepeatNumber(self, nums: List[int]) ->int: dic={}foriinnums:ifinotindic: dic[i]=1else:returnireturnFalse 思路:2. 数组哈希法,遍历数组,把序列[2,3,1,0,2,5,3]修改成一个下标和下标对应值是相同的数组[0,1,2,3,2,5,3] (nums[nums[i]] = nums[i]),寻找当前位(...
五、参考代码 class Solution { public int findRepeatNumber(int[] nums) { //设索引初始...
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...
0268 Missing Number Go 61.5% Easy 0269 Alien Dictionary 35.2% Hard 0270 Closest Binary Search Tree Value 54.5% Easy 0271 Encode and Decode Strings 41.3% Medium 0272 Closest Binary Search Tree Value II 58.2% Hard 0273 Integer to English Words 29.9% Hard 0274 H-Index Go 38.1% Medium...
Could you do it in one-pass, using only O(1) extra memory and without modifying the value of the board? 【解答】要数有多少 battleship,并且要求使用 O(1) 的空间复杂度,还不能修改 board 上的数值。 一行一行遍历,每一行中从左往右遍历。对于每一个点,如果左侧和上方都不是 X,那就...
Each rectangle is defined by its bottom left corner and top right corner as shown in the figure. Assume that the total area is never beyond the maximum possible value of int. 【解答】这个题目主要需要注意的是几种矩形放置情况,考虑二者位置之间的关系。先计算两个矩形的面积之和,考虑到计算过程中...
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...
class Solution { public: int findRepeatNumber(vector<int>& nums) { int n = nums.size(); sort(nums.begin(), nums.end()); for(int i=0; i<n; ++i) { if(nums[i] == nums[i+1]) { return nums[i]; } } return -1; } }; 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11....
Repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy. Return true if n is a happy number, and false if not. Example 1: Input: n = 19 Output: t ...