![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
贼心~不死
这个作者很懒,什么都没留下…
展开
-
前缀树相关
关于前缀树可以参考这篇非常不错的博文剑指Offer——Trie树(字典树)下面是利用前缀树的一道题:单词搜索 IIclass Solution { //构建前缀树 + dfs 深度遍历字符数组,然后和前缀树比较 //定义节点 static class TireNode{ //使用map 还是 数组 ...原创 2020-02-26 10:40:51 · 89 阅读 · 0 评论 -
211. 添加与搜索单词 - 数据结构设计
class WordDictionary { //使用什么来存储单词 ------>字典树?? //字典树 // 1 新建节点 static class TireNode{ boolean flag ; //记录该单词是否出现 Map<Character, TireNode> childNode; ...原创 2020-02-25 21:57:01 · 102 阅读 · 0 评论 -
leetcode62,63路径问题
62: public int uniquePaths(int m, int n) { int[][] dp = new int[m][n];//dp代表能走到当前点路径数 //初始化第0行边界值 for(int i = 0 ; i < n; i++) { dp[0][i] = 1; } ...原创 2019-12-16 21:31:37 · 85 阅读 · 0 评论 -
LeetCode61.旋转链表
public ListNode rotateRight(ListNode head, int k) { if(head == null||head.next == null) return head; int count = 0; ListNode l = head; int length =...原创 2019-12-16 19:20:46 · 65 阅读 · 0 评论 -
leetcode56合并区间
public int[][] merge(int[][] arr) { //根据第一个元素排序,快速排序 if(arr.length == 0) return new int[0][0]; if(arr.length == 1) return arr; boolean[] isvrist...原创 2019-12-16 09:31:08 · 64 阅读 · 0 评论 -
Leetcode45 跳跃游戏2
贪心算法,每次选能跳最远的 public int jump(int[] nums) { int ans = 0; for(int i = 0 ; i < nums.length ; i = maxjump(i,nums) ) { if(i == nums.length-1) break; ans++; } return a...原创 2019-12-13 12:42:52 · 66 阅读 · 0 评论 -
LeetCode42:接雨水问题
1,先寻找最高点2,左右两边分别向最高点遍历3,两值相加public int trap(int[] height) { if(height.length == 0)return 0; if(height.length == 1) return 0; int max = height[0]; int maxindex = 0;...原创 2019-12-13 09:58:21 · 143 阅读 · 0 评论 -
46. 全排列
动态规划class Solution { public List<List<Integer>> permute(int[] nums) { List<List<Integer>> result = new ArrayList<>(); permute(nums , 0 , num...原创 2019-06-28 21:39:18 · 90 阅读 · 0 评论 -
129. 求根到叶子节点数字之和
class Solution { int result; public int sumNumbers(TreeNode root) { if(root == null)return 0; sumNumber(root, 0); return result; } public void sumNumbe...原创 2019-06-27 22:53:27 · 81 阅读 · 0 评论 -
112. 路径总和
//递归 public boolean hasPathSum(TreeNode root, int sum) { if(root == null)return false; if(root.left == null && root.right ==null)return sum == root.val; return has...原创 2019-06-23 10:19:19 · 66 阅读 · 0 评论 -
leetcode 306. 累加数
class Solution { /** *先确认第一个数和第二个数,其中第三个数必须必第一个数的长度和第二个数的长度要长 *确认第一和第二个数之后,再用递归来验证是否是递增序列 */ public boolean isAdditiveNumber(String num) { //先要确认前两个数 in...原创 2019-06-22 10:28:38 · 154 阅读 · 0 评论 -
word-break
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens =“leetcode”,dict =[“leet”, “code...原创 2019-06-16 20:43:37 · 179 阅读 · 0 评论 -
leetcode(4)
ZigZag ConversionThe string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H...原创 2019-01-14 11:40:08 · 319 阅读 · 0 评论 -
leetcode练习(3)
Letter Combinations of a Phone Numberinput"23"output:[“ad”, “ae”, “af”, “bd”, “be”, “bf”, “cd”, “ce”, “cf”]根据题意2代表"abc",3代表"edf"backtracking(回溯算法)的题目代码:public List&lt;String&am原创 2019-01-14 11:22:49 · 107 阅读 · 0 评论