随笔分类 - 剑指offer
摘要:JZ42 连续子数组的最大和 /* 贪心 */ public class JZ42_1 { public static int FindGreatestSumOfSubArray(int[] array) { int sum = 0, res = Integer.MIN_VALUE; for (in
阅读全文
摘要:JZ58 左旋转字符串 /* 模拟 */ public class JZ58_1 { public static String LeftRotateString(String str, int n) { if (str.length() == 0) return ""; n %= str.lengt
阅读全文
摘要:JZ66 构建乘积数组 /* 暴力 */ public class JZ66_1 { public static int[] multiply(int[] A) { int[] res = new int[A.length]; Arrays.fill(res, 1); for (int i = 0;
阅读全文
摘要:JZ36 二叉搜索树与双向链表⭐ 1 /* 中序递归 */ 2 public class JZ36_1 3 { 4 public static TreeNode Convert(TreeNode pRootOfTree) 5 { 6 inOrder(pRootOfTree); 7 TreeNode
阅读全文
摘要:JZ55 二叉树的深度 1 /* 递归 */ 2 public class JZ55_1 3 { 4 public static int TreeDepth(TreeNode root) 5 { 6 if (root == null) return 0; 7 return Math.max(Tree
阅读全文
摘要:JZ3 数组中重复的数字⭐ 1 /* 2 * ① map/set 3 * ② 因为"长度为n的数组里的所有数字都在0到n-1的范围内" 4 * 所以对数组进行调整使得 numbers[idx]==idx 5 * */ 6 public class JZ3_1 7 { 8 public static
阅读全文
摘要:JZ65 不用加减乘除做加法⭐ 1 /* ^模拟不进位相加, &模拟进位(递归) */ 2 public class JZ65_1 3 { 4 public static int Add(int num1, int num2) 5 { 6 if (num2 == 0) return num1; 7
阅读全文
摘要:JZ53 数字在升序数组中出现的次数⭐ 1 /* 二分左边界 */ 2 public class JZ53_1 3 { 4 public static int GetNumberOfK(int[] nums, int k) 5 { 6 int left = 0, right = nums.lengt
阅读全文
摘要:JZ9 用两个栈实现队列 1 /* 模拟入队 */ 2 public class JZ9_1 3 { 4 public static Stack<Integer> stack1 = new Stack<Integer>(); 5 public static Stack<Integer> stack2
阅读全文
摘要:JZ12 矩阵中的路径 1 /* DFS */ 2 public class JZ12_1 3 { 4 public static boolean[][] vis; 5 public static int[] dx = new int[]{-1, 1, 0, 0}; 6 public static
阅读全文
摘要:JZ29 顺时针打印矩阵 1 /* 模拟 */ 2 public class JZ29_1 3 { 4 public static ArrayList<Integer> printMatrix(int[][] matrix) 5 { 6 ArrayList<Integer> res = new Ar
阅读全文
摘要:JZ6 从尾到头打印链表 1 /* 从尾到头递归 */ 2 public class JZ6_1 3 { 4 private static ArrayList<Integer> res = new ArrayList<>(); 5 6 public static ArrayList<Integer>
阅读全文