随笔分类 -  剑指offer系列

摘要:class Solution { public int maxValue(int[][] grid) { int rows = grid.length; int cols = grid[0].length; //int dp[0][0] = grid[0][0]; for(int i=0;i<row 阅读全文
posted @ 2020-12-16 19:07 peanut_zh 阅读(83) 评论(0) 推荐(0)
摘要://找规律法 class Solution { public int maxSubArray(int[] nums) { //全局变量标记是否输入无效 boolean isInvalidInput = false; if(nums == null || nums.length <= 0){ isIn 阅读全文
posted @ 2020-12-16 16:32 peanut_zh 阅读(67) 评论(0) 推荐(0)
摘要:class Solution { public int[] getLeastNumbers(int[] arr, int k) { if(k==0||arr.length<=0){ return new int[0]; } //默认是最小根堆,实现大根堆需要重写比较器 Queue<Integer> 阅读全文
posted @ 2020-12-16 13:17 peanut_zh 阅读(62) 评论(0) 推荐(0)
摘要:public class Solution { public int MoreThanHalfNum_Solution(int [] array) { //定义一个计数器count,存放众数的变量 card int card = 0; int count = 0; //找这个数字,一样就 计数加1, 阅读全文
posted @ 2020-12-16 11:29 peanut_zh 阅读(82) 评论(0) 推荐(0)
摘要:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ 阅读全文
posted @ 2020-12-15 17:06 peanut_zh 阅读(75) 评论(0) 推荐(0)
摘要:class Solution { public boolean verifyPostorder(int[] postorder) { return verifySquenceofBST(postorder,0,postorder.length-1); } boolean verifySquenceo 阅读全文
posted @ 2020-12-15 16:30 peanut_zh 阅读(101) 评论(0) 推荐(0)
摘要:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ 阅读全文
posted @ 2020-12-15 15:30 peanut_zh 阅读(101) 评论(0) 推荐(0)
摘要:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ 阅读全文
posted @ 2020-12-15 15:01 peanut_zh 阅读(87) 评论(0) 推荐(0)
摘要:import java.util.ArrayList; import java.util.Queue; import java.util.LinkedList; /** public class TreeNode { int val = 0; TreeNode left = null; TreeNo 阅读全文
posted @ 2020-12-15 14:51 peanut_zh 阅读(82) 评论(0) 推荐(0)
摘要:class Solution { public boolean validateStackSequences(int[] pushed, int[] popped) { Stack<Integer> stack = new Stack<>(); int index = 0; for(int x : 阅读全文
posted @ 2020-12-15 12:20 peanut_zh 阅读(77) 评论(0) 推荐(0)
摘要:class MinStack { Stack<Integer> A,B; /** initialize your data structure here. */ public MinStack() { A = new Stack<>(); B = new Stack<>(); } public vo 阅读全文
posted @ 2020-12-14 23:43 peanut_zh 阅读(42) 评论(0) 推荐(0)
摘要:class Solution { public int[] spiralOrder(int[][] matrix) { //判空 if(matrix.length == 0){ return new int[0]; } //定义矩阵 上下左右的边界 int left = 0; int right = 阅读全文
posted @ 2020-12-14 19:19 peanut_zh 阅读(82) 评论(0) 推荐(0)
摘要:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ 阅读全文
posted @ 2020-12-14 18:32 peanut_zh 阅读(42) 评论(0) 推荐(0)
摘要:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ 阅读全文
posted @ 2020-12-14 18:03 peanut_zh 阅读(29) 评论(0) 推荐(0)
摘要:/** public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; } } */ public class S 阅读全文
posted @ 2020-12-14 17:45 peanut_zh 阅读(66) 评论(0) 推荐(0)
摘要:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class Solution { 阅读全文
posted @ 2020-12-14 17:04 peanut_zh 阅读(41) 评论(0) 推荐(0)
摘要:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class Solution { 阅读全文
posted @ 2020-12-14 16:33 peanut_zh 阅读(52) 评论(0) 推荐(0)
摘要:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ //双指针法,2个指针遍历链表,其 阅读全文
posted @ 2020-12-14 14:36 peanut_zh 阅读(45) 评论(0) 推荐(0)
摘要://双指针法,left在前找偶数,right在后找奇数,交换。继续找,当俩个指针碰面,跳出 class Solution { public int[] exchange(int[] nums) { int left = 0, right = nums.length - 1; while(left < 阅读全文
posted @ 2020-12-14 14:22 peanut_zh 阅读(44) 评论(0) 推荐(0)
摘要:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class Solution { 阅读全文
posted @ 2020-12-14 13:26 peanut_zh 阅读(56) 评论(0) 推荐(0)