随笔分类 - leetcode
摘要:问题:多个数字相加,求无重复的组合有多少个? 思路:nSum回溯到2Sum class Solution: def fourSum(self, nums: List[int], target: int) -> List[List[int]]: return self.nSum(nums, targe
阅读全文
摘要:665. Non-decreasing Array Input: [4,2,3] Output: True Explanation: You could modify the first 4 to 1 to get a non-decreasing array.递增 思路:贪心思想,找异常值,存在两
阅读全文
摘要:563. Binary Tree Tilt 566. Reshape the Matrix 572. Subtree of Another Tree 581. Shortest Unsorted Continuous Subarray 594. Longest Harmonious Subseque
阅读全文
摘要:492. Construct the Rectangle Input: 4 Output: [2, 2] Explanation: The target area is 4, and all the possible ways to construct it are [1,4], [2,2], [4
阅读全文
摘要:448. Find All Numbers Disappeared in an Array 思路:把数组的内容和index进行一一对应映射,映射规则是取反,由此可知,重复出现两次的数字会变为正,出现一次的为负。 需要注意的是,如果不能增加额外空间的话,要在本数组上面进行映射,这时候就需要内容-1=i
阅读全文
摘要:53. Maximum Subarray Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return i
阅读全文
摘要:287. Find the Duplicate Number Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least on
阅读全文
摘要:对于大多数子字符串问题,我们获得一个字符串和需要寻找一个符合条件的子字符串。一个通常的解法是使用hashmap来关联两个指针,接下来是模板: 思路: 使用count作为匹配数 对于单个字符串匹配问题,直接用一个窗口滑动,右窗滑动并更改count值,使count值符合完全匹配条件;左窗滑动令count
阅读全文
摘要:350. Intersection of Two Arrays II 345. Reverse Vowels of a String 387. First Unique Character in a String 409. Longest Palindrome 412. Fizz Buzz 414.
阅读全文
摘要:235. Lowest Common Ancestor of a Binary Search Tree 公共的祖先必定大于左点小于右点,否则不断递归到合适。 257. Binary Tree Paths 258. Add Digits 263. Ugly Number 268. Missing Nu
阅读全文
摘要:198. House Robber 相邻不能打劫,取利益最大化。 思想:当前值和前一个和的总数 与 前一个和 做大小比较,取最大值,重复该步骤。 202. Happy Number 204. Count Primes 思路:在i × i 的基础上递进 i,这些都不是素数; 219. Contains
阅读全文
摘要:66、Plus One Given a non-empty array of digits representing a non-negative integer, plus one to the integer. The digits are stored such that the most s
阅读全文
摘要:38、Count and Say The count-and-say sequence is the sequence of integers with the first five terms as following: 1 is read off as "one 1" or 11.11 is r
阅读全文
摘要:21. Merge Two Sorted Lists Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of th
阅读全文
摘要:1、Two Sum Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input wou
阅读全文