摘要:
class Solution { public int removeDuplicates(int[] nums) { int i = 0; for (int n : nums) if (i < 2 || n > nums[i-2]) // 几个元素重复都可以用相同的方法 nums[i++] = n; 阅读全文
posted @ 2020-07-08 21:30
Sexyomaru
阅读(83)
评论(0)
推荐(0)
摘要:
class Solution { // 两种二分模版 public boolean searchMatrix(int[][] matrix, int target) { if(matrix.length == 0 || matrix[0].length == 0) return false; int 阅读全文
posted @ 2020-07-08 21:28
Sexyomaru
阅读(113)
评论(0)
推荐(0)
摘要:
class Solution { public void setZeroes(int[][] matrix) { int m = matrix.length; if(m == 0) return; int n = matrix[0].length; boolean row0 = false, col 阅读全文
posted @ 2020-07-08 21:27
Sexyomaru
阅读(159)
评论(0)
推荐(0)
摘要:
思路: 把当前目录压入栈中,遇到..弹出栈顶,最后返回栈中元素. class Solution { public String simplifyPath(String path) { String[] strs = path.split("/"); Stack<String> stack = new 阅读全文
posted @ 2020-07-08 21:25
Sexyomaru
阅读(107)
评论(0)
推荐(0)
摘要:
class Solution { public boolean isNumber(String s) { s = s.trim(); int n = s.length(); char[] arr = s.toCharArray(); boolean numSeen = false, dotSeen 阅读全文
posted @ 2020-07-08 21:23
Sexyomaru
阅读(160)
评论(0)
推荐(0)
摘要:
class Solution { public int mySqrt(int x) { if(x < 2) return x; int l = 0, r = x; while(l < r) { int mid = (l + r) >> 1; if(x / mid < mid) { r = mid; 阅读全文
posted @ 2020-07-08 21:21
Sexyomaru
阅读(147)
评论(0)
推荐(0)
摘要:
本题也可以使用回溯,但耗时太久,这里介绍数学统计的方法 class Solution { public String getPermutation(int n, int k) { StringBuilder sb = new StringBuilder(); boolean[] st = new b 阅读全文
posted @ 2020-07-08 21:11
Sexyomaru
阅读(90)
评论(0)
推荐(0)
摘要:
class Solution { List<String> res = new ArrayList<>(); public List<String> addOperators(String num, int target) { dfs(num,0,"",target,0,0); return res 阅读全文
posted @ 2020-07-08 21:07
Sexyomaru
阅读(169)
评论(0)
推荐(0)
摘要:
class Solution { public List<TreeNode> generateTrees(int n) { if(n == 0) return new ArrayList<>(); return build(1,n); } public List<TreeNode> build(in 阅读全文
posted @ 2020-07-08 21:03
Sexyomaru
阅读(101)
评论(0)
推荐(0)
摘要:
class Solution { public List<Integer> findSubstring(String s, String[] words) { List<Integer> res = new ArrayList<>(); int n = s.length(), m = words.l 阅读全文
posted @ 2020-07-08 21:01
Sexyomaru
阅读(159)
评论(0)
推荐(0)

浙公网安备 33010602011771号