Do it


  • Home

  • Tags

  • Archives

Leetcode 77

Posted on 2019-04-15 |
Words count in article: 79 | Reading time ≈ 1
Question Solution使用DFS,修改46题的代码。更改dfs嵌套的退出语句。 12345678910111213class Solution: def combine(self, n: int, k: int) -> List[List[int]]: resu ...
Read more »

Leetcode 60

Posted on 2019-04-14 |
Words count in article: 112 | Reading time ≈ 1
Question Solutionn个数,排列后,前(n-1)!个数以1开头,后(n-1)!个数以2开头。对于以1开头的部分,其中第一个(n-2)!部分以2开头…以此类推,可以确定所要的。 12345678910111213class Solution: def getPermutation( ...
Read more »

Leetcode 40/216

Posted on 2019-04-14 |
Words count in article: 160 | Reading time ≈ 1
Question1 SolutionDfs。需要注意的是相同的情况。 1234567891011121314151617class Solution: def combinationSum2(self, candidates: List[int], target: int) -> Lis ...
Read more »

Leetcode 39

Posted on 2019-04-14 |
Words count in article: 95 | Reading time ≈ 1
Question SolutionDfs来解。 先对candidates排序,然后对于candidates里面的每一个index遍历从其本身之后的所有元素。 123456789101112131415class Solution: def combinationSum(self, candid ...
Read more »

Leetcode 22

Posted on 2019-04-14 |
Words count in article: 103 | Reading time ≈ 1
Question SolutionDfs来做,考虑left和right的各自的次数,每添加一个就-1,然后通过判断语句来剔除不正确的情况。 12345678910111213141516class Solution: def generateParenthesis(self, n: int) ...
Read more »

Leetcode 17

Posted on 2019-04-13 |
Words count in article: 100 | Reading time ≈ 1
Question Solution考虑递归。每递归一次,digits都少一位,当digits为空的时候,递归返回一个结果。 12345678910111213141516171819202122232425class Solution: def letterCombinations(self, ...
Read more »

Leetcode 46

Posted on 2019-04-13 |
Words count in article: 261 | Reading time ≈ 1
Question1 Solution采用递归的方法。创建一个[False, False, …, False]的序列,如果一个数出现过了,就将其改为True。同时在递归返回结果后将数列恢复原样。 1234567891011121314151617181920212223class Solution: ...
Read more »

Leetcode 15. 3Sum

Posted on 2019-04-10 |
Words count in article: 191 | Reading time ≈ 1
Question Solution1将数据分为0,正数,负数。然后考虑000,-0+,-++,—+几种情况。 1234567891011121314151617181920212223242526272829303132333435class Solution: def threeSum(se ...
Read more »

Leetcode 769. Max Chunks To Make Sorted

Posted on 2019-04-10 |
Words count in article: 239 | Reading time ≈ 1
Question Solution1因为arr是1到n-1的排列,多以可以考虑将arr里面的数与其index之间的比较。创建一个空列表,向其中逐渐添加元素,每添加一个元素,就将小于这个元素的index的数从列表中删除,如果列表为空,则+1. 1234567891011121314class Solu ...
Read more »

Leetcode 835. Image Overlap

Posted on 2019-04-09 |
Words count in article: 341 | Reading time ≈ 1
Question Soltion1水平平移,可以有2(N-1)种,垂直方向也有2(N-1)。最简单的办法,遍历所有的情况,然后判断在当前的平移情况下,有多少是重叠的。 1234567891011121314class Solution: def largestOverlap(self, A: ...
Read more »
1…345…7
JW

JW

64 posts
14 tags
GitHub E-Mail
0%
© 2019 JW
Powered by Hexo
|
Theme — NexT.Pisces v5.1.4
访客数 人 总访问量 次