leetcode
小雨林夕
我这该死的无处安放的魅力啊!
展开
-
127. 单词接龙
class Solution { public int ladderLength(String beginWord, String endWord, List<String> wordList) { Set<String> dict = new HashSet<>(wordList); if(! dict.contains...原创 2019-11-01 14:48:22 · 137 阅读 · 0 评论 -
leetcode 1091. 二进制矩阵中的最短路径
class Solution { public int shortestPathBinaryMatrix(int[][] grid) { if (grid[0][0] == 1) { return -1; } int[][] direction = {{1,1},{1,0},{1,-1},{0,1},{0,-...原创 2019-10-31 16:23:20 · 185 阅读 · 0 评论 -
leetcode 763.划分字母区间
public List<Integer> partitionLabels(String S) { // 存放每个字母最后一次在字符串中出现的位置 int[] last = new int[26]; for (int i = 0; i < S.length(); ++i) { last[S.charAt...原创 2019-10-30 18:34:28 · 152 阅读 · 0 评论 -
leetcode-39.组合总和
刷题思路笔记,加油! 给定一个无重复元素的数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。 candidates 中的数字可以无限制重复被选取。 递归实现回溯法的深度优先搜索策略,带重复项的排列树,复杂度O(n!) 改进:先对 candidates.sort()排序,定义剪枝函数。 class Solution:...原创 2019-07-31 18:50:10 · 132 阅读 · 0 评论 -
leetcode-40.组合总和 II
给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。 candidates 中的每个数字在每个组合中只能使用一次。 思路,紧接上题,一开始想修改 self.dfs(nums,target-nums[i],i+1,temp+[nums[i]],res) 重复元素报错,解决,判断temp在不在res中: if...原创 2019-07-31 20:40:27 · 110 阅读 · 0 评论