![](https://img-blog.csdnimg.cn/20190927151117521.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
DFS
鸡蛋豆腐仙子
从本科开始讨厌了单片机 晶体管 编程 c++5-6年后,发现技术就是我的真爱,再重新选择一次,我还是会选择当程序员。我现在觉得自己什么都不会,可是还是相信会变成别人仰望的大神。
展开
-
【刷题】Leetcode 212. Word Search II
Example:Input:board = [[‘o’,‘a’,‘a’,‘n’],[‘e’,‘t’,‘a’,‘e’],[‘i’,‘h’,‘k’,‘r’],[‘i’,‘f’,‘l’,‘v’]]words = [“oath”,“pea”,“eat”,“rain”]Output: [“eat”,“oath”]避免有相同前缀的词重复查找比如“aaaaaax”, “aaaaaay” 所以...原创 2019-11-25 23:24:25 · 90 阅读 · 0 评论 -
【刷题】Leetcode 494. Target Sum
Example 1:Input: nums is [1, 1, 1, 1, 1], S is 3.Output: 5Explanation:-1+1+1+1+1 = 3+1-1+1+1+1 = 3+1+1-1+1+1 = 3+1+1+1-1+1 = 3+1+1+1+1-1 = 3There are 5 ways to assign symbols to make the sum ...原创 2019-12-08 18:51:08 · 44 阅读 · 0 评论 -
【刷题】Leetcode559. Maximum Depth of N-ary Tree
DFS:/*// Definition for a Node.class Node { public int val; public List<Node> children; public Node() {} public Node(int _val,List<Node> _children) { val = _va...原创 2019-11-02 19:41:08 · 116 阅读 · 0 评论 -
【刷题】Leetcode 131. Palindrome Partitioning
Example:Input: “aab”Output:[[“aa”,“b”],[“a”,“a”,“b”]]搜索顺序a a ba abaa baabclass Solution { public List<List<String>> partition(String s) { List<List<String>...原创 2019-10-30 21:08:18 · 76 阅读 · 0 评论 -
【刷题】Leetcode 46. Permutations
这道题还比较顺利,10-15分钟的样子可以搞定。Example:Input: [1,2,3]Output:[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]class Solution { public List<List<Integer>> permute(int[] nums) { ...原创 2019-10-26 20:36:09 · 98 阅读 · 0 评论 -
【刷题】Leetcode 77. Combinations
Example:Input: n = 4, k = 2Output:[[2,4],[3,4],[2,3],[1,2],[1,3],[1,4],]class Solution { public List<List<Integer>> combine(int n, int k) { List<List&...原创 2019-10-26 19:07:22 · 58 阅读 · 0 评论 -
【刷题】Leetcode 79. Word Search
Example:board =[[‘A’,‘B’,‘C’,‘E’],[‘S’,‘F’,‘C’,‘S’],[‘A’,‘D’,‘E’,‘E’]]Given word = “ABCCED”, return true.Given word = “SEE”, return true.Given word = “ABCB”, return false.做完 NQueen写了下面很傻逼的代码...原创 2019-10-26 10:19:24 · 154 阅读 · 0 评论 -
【刷题】Leetcode 934. Shortest Bridge
睡醒解决了个bug。In a given 2D binary array A, there are two islands. (An island is a 4-directionally connected group of 1s not connected to any other 1s.)Now, we may change 0s to 1s so as to connect the ...原创 2019-11-06 21:12:50 · 117 阅读 · 0 评论 -
【刷题】Leetcode 200. Number of Islands
Example 1:Input:11110110101100000000Output: 1Example 2:Input:11000110000010000011Output: 3class Solution { public int numIslands(char[][] grid) { int count = 0; for(i...原创 2019-11-04 22:20:40 · 67 阅读 · 0 评论 -
【刷题】Leetcode 784. Letter Case Permutation
Examples:Input: S = “a1b2”Output: [“a1b2”, “a1B2”, “A1b2”, “A1B2”]Input: S = “3z4”Output: [“3z4”, “3Z4”]Input: S = “12345”Output: [“12345”]class Solution { public List<String> letter...原创 2019-10-28 16:51:37 · 69 阅读 · 0 评论 -
【刷题】Leetcode 78. Subsets
Example:Input: nums = [1,2,3]Output:[[3],[1],[2],[1,2,3],[1,3],[2,3],[1,2],[]]这道题就是combination的基础上,把每个组合输出出来。不用限制组合长度。10 / 10 test cases passed.Status: AcceptedRuntime: 1 msMemory Usa...原创 2019-10-28 16:41:11 · 67 阅读 · 0 评论 -
【刷题】Leetcode 17. Letter Combinations of a Phone Number
刷了两天题,好像以前不会的东西现在可以做出来了。把搜索的做一做之后会写一个总结,现在是把每道题都单独写出来了。而且我发现我没有写注释。。。。。Example:Input: “23”Output: [“ad”, “ae”, “af”, “bd”, “be”, “bf”, “cd”, “ce”, “cf”].思路:图转自b站花花酱class Solution { publi...原创 2019-10-28 09:34:05 · 135 阅读 · 0 评论 -
【刷题Leetcode 39. Combination Sum
Example 1:Input: candidates = [2,3,6,7], target = 7,A solution set is:[[7],[2,2,3]]在combination基础上刷这道题,主要是递归层数这个地方。for(int i = n; i < candidates.length; i++){list.add(candidates[i]);helpe...原创 2019-10-27 16:15:35 · 76 阅读 · 0 评论