![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
每日一题基础版
米兰的小红黑
这个作者很懒,什么都没留下…
展开
-
剑指offer基础版 ----第31天
class Solution { public int cuttingRope(int n) { if(n <= 3) return n - 1; int b = n % 3, p = 1000000007; long ret = 1; int lineNums=n/3; //线段被我们分成以3为大小的小线段个数 for(int i=1;i<lineNums;i.原创 2021-12-17 21:08:50 · 64 阅读 · 0 评论 -
剑指offer基础版--- 第23天
class Solution { public int majorityElement(int[] nums) { Arrays.sort(nums); return nums[nums.length / 2]; }}class Solution { public int[] constructArr(int[] a) { int len = a.length; if(len == 0) return new .原创 2021-12-15 21:55:31 · 430 阅读 · 0 评论 -
剑指offer基础版 ---- 第29天
class Solution { public boolean isMatch(String s, String p) { int m = s.length(); int n = p.length(); boolean[][] f = new boolean[m + 1][n + 1]; f[0][0] = true; for (int i = 0; i <= m; ++i) { for.原创 2021-12-15 19:18:42 · 464 阅读 · 0 评论 -
剑指offer基础版 ----- 第28天
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Codec { public String serialize(TreeNode root) { return.原创 2021-12-14 18:25:48 · 55 阅读 · 0 评论 -
剑指offer基础版 ---- 第27天
class Solution { public int[] maxSlidingWindow(int[] nums, int k) { if(nums.length == 0 || k == 0) return new int[0]; Deque<Integer> deque = new LinkedList<>(); int[] res = new int[nums.length - k + 1]; for(.原创 2021-12-08 22:24:55 · 65 阅读 · 0 评论 -
剑指offer基础版 ---- 第26天
class Solution { public int strToInt(String str) { char[] arr = str.trim().toCharArray(); if(arr.length == 0){ return 0; } int i = 1; int sign = 1; long res = 0; int sum = Integer.MA.原创 2021-12-07 14:16:41 · 58 阅读 · 0 评论 -
剑指offer基础版 ----- 第25天
class Solution { public int[] spiralOrder(int[][] matrix) { if(matrix.length == 0){ return new int[0]; } int[] arr = new int[matrix.length * matrix[0].length]; List<Integer> list= new ArrayList<>.原创 2021-12-06 21:58:41 · 46 阅读 · 0 评论 -
剑指offer基础版 --- 第24天
class Solution { public int cuttingRope(int n) { int[] dp = new int[n + 1]; dp[2] = 1; for(int i = 3; i <= n; i++){ for(int j = 2; j < i; j++){ dp[i] = Math.max(dp[i],Math.max(j * (i - j),j * d.原创 2021-12-05 21:07:08 · 51 阅读 · 0 评论 -
剑指offer基础版 --- 第22天
class Solution { public int[] singleNumbers(int[] nums) { int ret = 0; for(int num : nums){ ret = ret ^ num; } int target = 1; while((target & ret) == 0){ target = target << 1;.原创 2021-12-05 16:42:29 · 47 阅读 · 0 评论 -
剑指offer基础版 --- 第21天
public class Solution { // you need to treat n as an unsigned value public int hammingWeight(int n) { int x = 0; while(n != 0){ if((n & 1) == 1){ x++; n = n >>> 1; .原创 2021-12-03 13:55:40 · 46 阅读 · 0 评论 -
剑指offer基础版----第20天
class Solution { private Map<Integer, Integer> indexMap; public TreeNode myBuildTree(int[] preorder, int[] inorder, int preorder_left, int preorder_right, int inorder_left, int inorder_right) { if (preorder_left > preorder_right).原创 2021-12-02 21:39:16 · 57 阅读 · 0 评论 -
剑指offer基础版---第19天
class Solution { public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { if(root == null){ return null; } if(root == p || root == q){ return root; } TreeNode left = .原创 2021-12-01 12:59:43 · 3322 阅读 · 0 评论 -
剑指offer基础版 ---- 第18天
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { public int maxDepth(TreeNode root) { if(root == nul.原创 2021-11-30 19:19:57 · 54 阅读 · 0 评论 -
剑指offer基础版----第16天
class Solution { public String minNumber(int[] nums) { String[] strs = new String[nums.length]; for(int i = 0; i < nums.length; i++) strs[i] = String.valueOf(nums[i]); quickSort(strs, 0, strs.length - 1); .原创 2021-11-27 10:55:28 · 178 阅读 · 0 评论 -
剑指offer基础版----15天
class Solution { List<List<Integer>> list = new ArrayList<>(); List<Integer> list1 = new ArrayList<>(); public List<List<Integer>> pathSum(TreeNode root, int target) { recur(root,target); .原创 2021-11-26 17:38:15 · 80 阅读 · 0 评论 -
剑指offer基础版-----第14天
class Solution { public boolean exist(char[][] board, String word) { char[] words = word.toCharArray(); for(int i = 0; i < board.length; i++) { for(int j = 0; j < board[0].length; j++) { if(dfs(board, .原创 2021-11-25 20:44:59 · 154 阅读 · 0 评论 -
java多线程基础版----第12天
class Solution { public ListNode mergeTwoLists(ListNode l1, ListNode l2) { ListNode pre1 = new ListNode(-1); ListNode pre = pre1; while(l1 != null && l2 != null){ if(l1.val < l2.val){ pre..原创 2021-11-22 15:52:04 · 608 阅读 · 0 评论 -
剑指offer基础版----第11天
class Solution { public ListNode deleteNode(ListNode head, int val) { ListNode pre = new ListNode(-1); pre.next = head; ListNode cur1 = pre; ListNode cur2 = head; while(cur2 != null){ if(cur2.val ==.原创 2021-11-21 16:38:03 · 159 阅读 · 0 评论 -
剑指offer基础版---第10天
class Solution { public int translateNum(int num) { String src = String.valueOf(num); int p = 1; int q = 1; int r = 1; for(int i = 0; i < src.length(); i++){ if(i == 0){ continue;.原创 2021-11-20 22:03:25 · 267 阅读 · 0 评论 -
剑指offer基础版---第九天
class Solution { public int maxSubArray(int[] nums) { int res = Integer.MIN_VALUE; int tmp = 0; for(int i = 0; i < nums.length; i++){ if(tmp + nums[i] <= nums[i]){ tmp = nums[i]; }e.原创 2021-11-18 21:46:57 · 63 阅读 · 0 评论 -
剑指offer基础版----第8天
class Solution { public int fib(int n) { if(n == 0){ return 0; } int a = 1; int b = 1; int res = 1; for(int i = 0; i < n-2;i++){ res = (a+b)%1000000007; a = b; .原创 2021-11-17 20:05:26 · 62 阅读 · 0 评论 -
剑指offer基础版----第7天
class Solution { public boolean isSubStructure(TreeNode A, TreeNode B) { if(B == null){ return false; } if(A == null){ return false; } if(compare(A,B)){ return true; }.原创 2021-11-16 15:54:39 · 61 阅读 · 0 评论 -
剑指offer基础版---第六天
class Solution { public int[] levelOrder(TreeNode root) { if(root == null) { return new int[0]; } Queue<TreeNode> queue = new LinkedList<>(); List<Integer> list = new ArrayList<>(); .原创 2021-11-15 14:17:45 · 372 阅读 · 0 评论 -
剑指offer基础版----第五天
class Solution { public boolean findNumberIn2DArray(int[][] matrix, int target) { if (matrix == null || matrix.length == 0 || matrix[0].length == 0) { return false; } int rows = matrix.length, columns = matrix[0].le.原创 2021-11-15 13:08:27 · 61 阅读 · 0 评论 -
剑指offer基础版---第四天
class Solution { public int findRepeatNumber(int[] nums) { int i = 0; while(i < nums.length) { if(nums[i] == i) { i++; continue; } if(nums[nums[i]] == nums[i]) retu.原创 2021-11-09 17:34:37 · 3955 阅读 · 0 评论 -
剑指offer基础版---第三天
class Solution { public String replaceSpace(String s) { return s.replace(" ","%20"); }}class Solution { public String reverseLeftWords(String s, int n) { int tmp = s.length(); int num = n % tmp; return s.s.原创 2021-11-08 17:05:40 · 66 阅读 · 0 评论 -
剑指offer普通版---第二天
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { public int[] reversePrint(ListNode head) { Stack<ListNode> stack = n.原创 2021-11-08 17:03:12 · 192 阅读 · 0 评论 -
剑指offer普通版---第一天
class CQueue { Stack<Integer> stack1 = new Stack<>(); Stack<Integer> stack2 = new Stack<>(); public CQueue() { } public void appendTail(int value) { stack1.push(value); } public int .原创 2021-11-03 15:28:13 · 63 阅读 · 0 评论