上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 36 下一页
摘要: 深度优先搜索 class Solution { List<Integer> list = new LinkedList<>(); public List<Integer> postorder(Node root) { if (root == null){ return list; } for (No 阅读全文
posted @ 2022-02-21 14:52 振袖秋枫问红叶 阅读(21) 评论(0) 推荐(0)
摘要: 深度优先搜索 class Solution { List<Integer> list = new LinkedList<>(); public List<Integer> preorder(Node root) { if (root == null){ return list; } list.add 阅读全文
posted @ 2022-02-21 14:40 振袖秋枫问红叶 阅读(19) 评论(0) 推荐(0)
摘要: 广度优先搜索 class Solution { public Node connect(Node root) { Queue<Node> queue = new LinkedList<>(); if (root == null){ return root; } queue.add(root); wh 阅读全文
posted @ 2022-02-21 13:54 振袖秋枫问红叶 阅读(25) 评论(0) 推荐(0)
摘要: 广度优先搜索 class Solution { public Node connect(Node root) { Queue<Node> queue = new LinkedList<>(); if (root == null){ return root; } queue.add(root); wh 阅读全文
posted @ 2022-02-21 13:50 振袖秋枫问红叶 阅读(26) 评论(0) 推荐(0)
摘要: 广度优先搜索 class Solution { public List<Integer> largestValues(TreeNode root) { LinkedList<Integer> list = new LinkedList<>(); Queue<TreeNode> queue = new 阅读全文
posted @ 2022-02-21 13:05 振袖秋枫问红叶 阅读(30) 评论(0) 推荐(0)
摘要: 广度优先搜索 class Solution { public List<List<Integer>> levelOrder(Node root) { List<List<Integer>> list = new LinkedList<>(); Queue<Node> queue = new Link 阅读全文
posted @ 2022-02-21 12:05 振袖秋枫问红叶 阅读(29) 评论(0) 推荐(0)
摘要: 广度优先搜索 class Solution { public List<Double> averageOfLevels(TreeNode root) { List<Double> list = new LinkedList<>(); Queue<TreeNode> queue = new Linke 阅读全文
posted @ 2022-02-21 11:46 振袖秋枫问红叶 阅读(23) 评论(0) 推荐(0)
摘要: 双端队列实现单调队列 import java.util.ArrayDeque; class Solution { public int[] maxSlidingWindow(int[] nums, int k) { /** * 双端队列实现单调队列 * 队列存储的是元素的索引 */ Deque<In 阅读全文
posted @ 2022-02-20 11:26 振袖秋枫问红叶 阅读(35) 评论(0) 推荐(0)
摘要: 栈 import java.util.Stack; class Solution { public String removeDuplicates(String s) { Stack<Character> stack = new Stack(); for (int i = 0; i < s.leng 阅读全文
posted @ 2022-02-19 22:48 振袖秋枫问红叶 阅读(54) 评论(0) 推荐(0)
摘要: class Solution { public boolean repeatedSubstringPattern(String s) { /** * 将一个字符串复制两份,然后去掉首尾元素,如果剩余的子串中还包含原字符串,说明原字符串含有重复的子串 */ String str = s + s; re 阅读全文
posted @ 2022-02-19 20:57 振袖秋枫问红叶 阅读(31) 评论(0) 推荐(0)
上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 36 下一页