![](https://img-blog.csdnimg.cn/20190918140129601.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
leetcode
文章平均质量分 83
刷题日常
伯春岱
这个作者很懒,什么都没留下…
展开
-
热题100刷题记录
热题100刷题顺序:按照难易程度排序3/8/2021 7/1001.两数之和题目时间3/8/2021解题思路c++代码class Solution {public: vector<int> twoSum(vector<int>& nums, int target) { vector<int> ans; int size=nums.size(); for(int i=0;i<size;i++)原创 2021-03-08 14:10:38 · 114 阅读 · 0 评论 -
【专题】动态规划
【专题】动态规划刷题顺序来自https://leetcode-cn.com/circle/article/48kq9d/文章目录【专题】动态规划更新记录数组中的动态规划[509. 斐波那契数](https://leetcode-cn.com/problems/fibonacci-number/)[70. 爬楼梯](https://leetcode-cn.com/problems/climbing-stairs/)[338. 比特位计数](https://leetcode-cn.com/problems原创 2021-01-30 17:47:30 · 112 阅读 · 0 评论 -
【leetcode0131】分割回文串
代码private List<List<String>> res = new ArrayList<>(); public List<List<String>> partition(String s) { if(s.length()==0) return res; backtrack(s,new ArrayList...原创 2020-02-19 15:15:32 · 62 阅读 · 0 评论 -
【leetcode0126】单词接龙 II(超时)
代码private int min = 99999; private List<List<String>> res = new ArrayList<>(); public List<List<String>> findLadders(String beginWord, String endWord, List<String&...原创 2020-02-19 14:40:12 · 125 阅读 · 0 评论 -
【leetcode0090】子集 II
代码private List<List<Integer>> res=new ArrayList<>(); public List<List<Integer>> subsetsWithDup(int[] nums) { Arrays.sort(nums); boolean[] choose=new boolean[nums.le...原创 2020-02-19 09:59:40 · 79 阅读 · 0 评论 -
【leetcode0089】格雷编码
代码 public List<Integer> grayCode(int n) { List<Integer> gray = new ArrayList<Integer>(); gray.add(0); //初始化 n = 0 的解 for (int i = 0; i < n; i++) { int add ...转载 2020-02-19 09:42:53 · 84 阅读 · 0 评论 -
【leetcode0079】单词搜索
思路代码public boolean exist(char[][] board, String word) { boolean[][] choose=new boolean[board.length][board[0].length]; for(int i=0;i<board.length;i++) { for(int j=0;j<board[0].length;j...原创 2020-02-19 09:23:14 · 87 阅读 · 0 评论 -
【leetcode0078】子集
思路套回溯框架代码private List<List<Integer>> res = new ArrayList<>(); public List<List<Integer>> subsets(int[] nums) { List<Integer> path = new ArrayList<>();...原创 2020-02-18 22:54:58 · 67 阅读 · 0 评论 -
【leetcode0077】组合
思路套用回溯模板代码private List<List<Integer>> res=new ArrayList<>(); public List<List<Integer>> combine(int n, int k) { List<Integer> path=new ArrayList<>();...原创 2020-02-18 22:29:00 · 63 阅读 · 0 评论 -
【leecode0060】第k个排列
思路代码public String getPermutation(int n, int k) { int[] fac= {0,1,2,6,24,120,720,5040,40320,362880,3628800}; String res=""; String s="123456789".substring(0,n); --k; while(k>0) { int...原创 2020-02-18 22:13:41 · 97 阅读 · 0 评论 -
【leetcode0051&0052】N皇后&N皇后2
小技巧回溯法字符数组转化为字符串思路代码private List<List<String>> res=new ArrayList<>(); public List<List<String>> solveNQueens(int n) { char[][] board=new char[n][n]; for (c...原创 2020-02-18 20:47:12 · 60 阅读 · 0 评论 -
【leetcode0047】全排列II
思路和46类似,要考虑去重;由于相同的数字走过的路径相同,那么相同的数字要么一起选,要么只用选择其中一个作为分叉点。代码private List<List<Integer>> res = new ArrayList<>(); public List<List<Integer>> permuteUnique(int[] nums)...原创 2020-02-17 18:48:51 · 61 阅读 · 0 评论 -
【leetcode0046】全排列
思路不需要剪枝的回溯算法,照模板写即可代码private List<List<Integer>> res =new ArrayList<>(); public List<List<Integer>> permute(int[] nums) { if(nums.length==0) return res; bool...原创 2020-02-17 18:05:35 · 63 阅读 · 0 评论 -
【leetcode0044】通配符匹配(回溯法时间超了,等动态规划的时候重新改)
思路代码public boolean isMatch(String s, String p) { if(p.isEmpty()) return s.isEmpty()? true:false; if(s.isEmpty()) return p.charAt(0)=='*'? isMatch(s,p.substring(1)):false; if(p.charAt(0)...原创 2020-02-17 17:22:38 · 98 阅读 · 0 评论 -
【leetcode0037】解数独
思路代码public class Solution0037 { private boolean row[][]=new boolean[9][10]; private boolean col[][]=new boolean[9][10]; private boolean sqr[][][]=new boolean[3][3][10]; public void solveSud...原创 2020-02-17 15:48:04 · 103 阅读 · 0 评论 -
【leetcode0022】括号生成
思路代码public class Solution0022 { List<String> res = new ArrayList<>(); public List<String> generateParenthesis(int n) { if(n==0) return res; backtrack("",n,0); ret...原创 2020-02-17 14:16:19 · 63 阅读 · 0 评论 -
【leetcode0017】电话号码的字母组合
思路代码public class Solution0017 { private List<String> result =new ArrayList<>(); private String[] map= { "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz...原创 2020-02-17 13:46:41 · 305 阅读 · 0 评论 -
【leetcode0010】正则表达式匹配
解题思路代码public boolean isMatch(String s, String p) { if(p.isEmpty()) return s.isEmpty()? true:false; if(s==p) return true; boolean firstMatched=!s.isEmpty()&&(s.charAt(0)==p.charA...原创 2020-02-17 12:42:29 · 94 阅读 · 0 评论