![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
m1f2c3
这个作者很懒,什么都没留下…
展开
-
LeetCode之Nim Game
bool canWinNim(int n) { return (n%4 != 0);}原创 2015-10-24 20:53:31 · 545 阅读 · 0 评论 -
1026. Maximum Difference Between Node and Ancestor
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { pub...原创 2019-07-25 21:42:06 · 108 阅读 · 0 评论 -
17. Letter Combinations of a Phone Number
class Solution { public List<String> letterCombinations(String digits) { if(digits.length() == 0){ return new ArrayList<>(); } String[][] digits_arr...原创 2019-07-26 22:13:52 · 81 阅读 · 0 评论 -
10. Regular Expression Matching
用dp做的class Solution { public boolean isMatch(String s, String p) { int len_s = s.length(); int len_p = p.length(); boolean[][] mem = new boolean[len_p + 1][len_s + 1];...原创 2019-08-08 10:32:33 · 64 阅读 · 0 评论 -
32. Longest Valid Parentheses
参照这个代码改的,运用了dphttps://leetcode.com/problems/longest-valid-parentheses/discuss/353653/Pure-python-DPclass Solution { public int longestValidParentheses(String s) { int[] mem = new int[...原创 2019-08-08 15:31:32 · 70 阅读 · 0 评论 -
44. 通配符匹配
leetcode网站维护,只能去力扣了class Solution { public boolean isMatch(String s, String p) { boolean[][] dp = new boolean[p.length() + 1][s.length() + 1]; dp[0][0] = true; for(int i =...原创 2019-08-08 18:50:55 · 86 阅读 · 0 评论 -
62. Unique Paths
class Solution { public int uniquePaths(int m, int n) { if(m == 0 || n == 0){return 0;} int[][] dp = new int[m][n]; for(int i = 0; i < m; ++i){dp[i][0] = 1;} fo...原创 2019-08-08 22:01:13 · 62 阅读 · 0 评论 -
869. Reordered Power of 2
class Solution { int[][] mem = new int[30][10]; public boolean reorderedPowerOf2(int N) { mem[0][1] = 1; int chengji = 1; for(int i = 1; i < mem.length; ++i){ ...原创 2019-08-06 22:05:35 · 107 阅读 · 0 评论 -
1092. Shortest Common Supersequence
没做出来,但是答案的思路很牛逼https://leetcode.com/problems/shortest-common-supersequence/discuss/319439/Java-DP-bottom-up-(2D-matrix)原创 2019-08-09 15:16:09 · 132 阅读 · 0 评论 -
1129. Shortest Path with Alternating Colors
这道题的思路跟1091. Shortest Path in Binary Matrix是一样的class Solution { public int[] shortestAlternatingPaths(int n, int[][] red_edges, int[][] blue_edges) { int[][] nn_red = new int[n][n];...原创 2019-08-07 15:57:59 · 229 阅读 · 0 评论 -
820. Short Encoding of Words
class Solution { public int minimumLengthEncoding(String[] words) { StringBuffer sb_array = new StringBuffer(); String[] str_array = new String[words.length]; for(int i = 0...原创 2019-08-07 18:42:07 · 375 阅读 · 0 评论 -
55. 跳跃游戏
跳跃游戏给定一个非负整数数组,你最初位于数组的第一个位置。数组中的每个元素代表你在该位置可以跳跃的最大长度。判断你是否能够到达最后一个位置。示例 1:输入: [2,3,1,1,4]输出: true解释: 从位置 0 到 1 跳 1 步, 然后跳 3 步到达最后一个位置。示例 2:输入: [3,2,1,0,4]输出: false解释: 无论怎样,你总会到达索引为 3 的位置...原创 2019-08-28 09:48:17 · 110 阅读 · 0 评论 -
253. 会议室 II———使用优先队列或者拆分的方法
给定一个会议时间安排的数组,每个会议时间都会包括开始和结束的时间 [[s1,e1],[s2,e2],…] (si < ei),为避免会议冲突,同时要考虑充分利用会议室资源,请你计算至少需要多少间会议室,才能满足这些会议安排。示例 1:输入: [[0, 30],[5, 10],[15, 20]]输出: 2示例 2:输入: [[7,10],[2,4]]输出: 1来源:力扣(Leet...原创 2019-08-29 15:43:36 · 264 阅读 · 0 评论 -
5132. Shortest Path with Alternating Colors
这题压根没看懂原创 2019-07-21 11:59:04 · 187 阅读 · 0 评论 -
5130. Number of Equivalent Domino Pairs
class Solution { public int numEquivDominoPairs(int[][] dominoes) { List<int[]> dom_list = new ArrayList<>(); for(int i = 0; i < dominoes.length; ++i){ d...原创 2019-07-21 11:58:32 · 153 阅读 · 0 评论 -
5133. Maximum of Absolute Value Expression
class Solution { public int maxAbsValExpr(int[] arr1, int[] arr2) { int sum = Integer.MIN_VALUE; for(int i = 0; i < arr1.length + 1; ++i){ for(int j = i + 1; j < ...原创 2019-07-21 11:57:48 · 199 阅读 · 0 评论 -
LeetCode之Game of Life
void gameOfLife(int** board, int boardRowSize, int boardColSize) { //int** pp_Game = pp_Create((boardRowSize + 2), (boardColSize + 2)); int i = 0, j = 0; ////////////////////////////////创造pp_Gam原创 2015-10-24 20:55:21 · 442 阅读 · 0 评论 -
将宽度优先序列转换成二叉树并可视化
display函数输入是二叉树,输出是将二叉树打印出来(节点值不能是0)效果如下代码public class Niuke0417 { public static void main(String[] args) { TreeNode a1 = new TreeNode(4); TreeNode a2_1 = new TreeNode(10); ...原创 2019-06-10 21:17:34 · 183 阅读 · 0 评论 -
15. 3Sum
class Solution { public List<List<Integer>> threeSum(int[] nums) { Arrays.sort(nums); List<List<Integer>> res_list = new ArrayList<>(); for(in...原创 2019-07-04 21:35:20 · 61 阅读 · 0 评论 -
1093. Statistics from a Large Sample
class Solution { public double[] sampleStats(int[] count) { double min = -1; double max = -1; double mean = 0; double median = 0; double mode = 0; ...原创 2019-07-07 14:53:56 · 194 阅读 · 0 评论 -
1095. Find in Mountain Array
/** * // This is MountainArray's API interface. * // You should not implement it, or speculate about its implementation * interface MountainArray { * public int get(int index) {} * public...原创 2019-07-07 14:55:33 · 189 阅读 · 0 评论 -
1109. Corporate Flight Bookings
class Solution { public int[] corpFlightBookings(int[][] bookings, int n) { int[] res_array = new int[n]; for(int[] mem : bookings){ for(int j = mem[0]; j <= mem[1];...原创 2019-07-07 14:56:26 · 221 阅读 · 0 评论 -
1110. Delete Nodes And Return Forest
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { publ...原创 2019-07-07 14:57:04 · 207 阅读 · 0 评论 -
105. Construct Binary Tree from Preorder and Inorder Traversal
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { publ...原创 2019-07-18 20:59:25 · 54 阅读 · 0 评论 -
16. 3Sum Closest
class Solution { public int threeSumClosest(int[] nums, int target) { Arrays.sort(nums); int result = nums[0] + nums[1] + nums[2]; for(int i = 0; i < nums.length - 2; +...原创 2019-07-19 20:53:27 · 69 阅读 · 0 评论 -
106. Construct Binary Tree from Inorder and Postorder Traversal
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { publ...原创 2019-07-17 21:17:24 · 65 阅读 · 0 评论 -
889. Construct Binary Tree from Preorder and Postorder Traversal
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { pub...原创 2019-07-17 21:18:30 · 116 阅读 · 0 评论 -
5131. Minimum Cost Tree From Leaf Values
这题没做出来原创 2019-07-21 11:56:45 · 122 阅读 · 0 评论 -
903. DI 序列的有效排列(2019爱奇艺秋招笔试题之一)
我们给出 S,一个源于 {‘D’, ‘I’} 的长度为 n 的字符串 。(这些字母代表 “减少” 和 “增加”。)有效排列 是对整数 {0, 1, …, n} 的一个排列 P[0], P[1], …, P[n],使得对所有的 i:如果 S[i] == ‘D’,那么 P[i] > P[i+1],以及;如果 S[i] == ‘I’,那么 P[i] < P[i+1]。有多少个有效排列...原创 2019-09-08 17:34:01 · 3475 阅读 · 0 评论