- 博客(4)
- 收藏
- 关注
原创 有关辅助栈的使用场景
辅助栈的使用:@Test//(剑指 Offer 31. 栈的压入、弹出序列) public void test31() { int[] pushed = {1, 2, 3, 4, 5}; int[] popped = {4, 5, 3, 2, 1}; System.out.println(validateStackSequences(pushed, popped)); } public static boolean valid
2022-04-27 09:38:30
254
原创 有关二叉树中使用递归解决的问题:
有关二叉树找公共祖先的问题:#情况一:二叉树为二叉搜索树:(根据二叉搜索树的特性,使用一次遍历即可)//root为根结点,找结点p和q的公共祖先:public static TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { TreeNode temp = root; while (true) { if (temp.val > p.val &am
2022-04-26 11:05:19
888
原创 有关字符串去空格问题
\\s+可以替换掉关键字之间的所有空白字符(剑指 Offer 58 - I. 翻转单词顺序)@Test public void test58(){ System.out.println(reverseWords(" hello world!")); } public static String reverseWords(String s) { String s2 = s.trim(); String[] s1 = s2.s
2022-04-24 12:39:38
114
原创 大顶堆、小顶堆的使用
大顶堆、小顶堆的使用Java 使用 PriorityQueue<>((x, y) -> (y - x)) 可方便实现大顶堆。默认new的PriorityQueue为小顶堆结构@Test//这里用来测试小顶堆与大顶堆 public void test(){ Queue<Integer> queue = new PriorityQueue<>(); queue.offer(5); queue.offer(
2022-04-22 09:51:49
703
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人