09 2019 档案
摘要:思路:跟三数之和的思路相同,只不过这里是最接近target的三个数,同样将数组排序,固定第一个数,后面两个数用双指针移动,当三个数的和大于target,那么将右边指针左移,如果三个数的和小于target,那么将左边指针右移。 python class Solution(object): def th
阅读全文
摘要:思路:先固定一个数,然后剩下两个数用双指针,这样可以O(n2)时间完成 python class Solution(object): def threeSum(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ num
阅读全文
摘要:思路:https://leetcode cn.com/problems/integer to roman/solution/tan xin suan fa by liweiwei1419/
阅读全文
摘要:思路:用两个指针,因为指针往里面缩小,容器的宽度会减少,因此需要通过增加高度来抵消宽度的减少,因此移动高度短的指针期望寻找到更高的来替代,要不然面积会越来越小 python class Solution(object): def maxArea(self, height): """ :type he
阅读全文
摘要:思路:遍历所有元素,从当前元素向两边扩展,如果两边相同那么可以拓展,回文串长度加2,如此循环。
阅读全文
摘要:思路:因为数是用链表逆序表示的,因此先用列表将这些数提取出来。然后每一位对应相加大于10就进位,进位用carry表示。有两个特殊情况要考虑:(1)象5+5这种,两个数的位数一样,最后要增加一位。(2)象1+99这种,两个数的位数不一样,先将1+9相加跳出循环,后面是carry+9=10,又出现了一个
阅读全文
摘要:思路:见题解https://leetcode cn.com/problems/arithmetic slices/solution/deng chai shu lie hua fen by leetcode/ python class Solution(object): def numberOfAr
阅读全文
摘要:思路: 新建一个跟数组一样大的dp表,dp[i][j]表示经过A[i][j]点时最小的路径和。 python class Solution(object): def minFallingPathSum(self, A): """ :type A: List[List[int]] :rtype: in
阅读全文

浙公网安备 33010602011771号