上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 17 下一页
摘要: Same: Both of Stack and Dequeu can be a stack. Differences: 1. Deque is a LinkedList, Stack is a Stack. 2. Dequeu can getFirst() and getLast(), but St 阅读全文
posted @ 2022-02-05 09:39 阳光明媚的菲越 阅读(29) 评论(0) 推荐(0) 编辑
摘要: This problem should not use DFS to solve it, I have tried, but failed with this test case: [3,9,8,4,0,1,7,null,null,null,2,5] My output is: [[4],[9,5] 阅读全文
posted @ 2022-02-05 08:50 阳光明媚的菲越 阅读(21) 评论(0) 推荐(0) 编辑
摘要: This is a Iterator problem too, the soltuion is: 1. keep a variable, nextInt, to store the potential next Integer. 2. when peek(), if the nextInt is n 阅读全文
posted @ 2022-02-05 07:55 阳光明媚的菲越 阅读(24) 评论(0) 推荐(0) 编辑
摘要: This is an itegrator problem. You can look nestedList as a tree, just recursively read the nestedList, and put the integration into a list, and then i 阅读全文
posted @ 2022-02-05 07:50 阳光明媚的菲越 阅读(15) 评论(0) 推荐(0) 编辑
摘要: This is a similar problem with "543. Diameter of Binary Tree", the only difference is 543 is a binary tree, and 1522 is an n_ary tree. For 1522, we ne 阅读全文
posted @ 2022-02-05 05:00 阳光明媚的菲越 阅读(19) 评论(0) 推荐(0) 编辑
摘要: This is a Post Order binary tree problem. For every node, we need to know its left tree's maximal diameter and its right tree's maximal diameter, and 阅读全文
posted @ 2022-02-05 03:31 阳光明媚的菲越 阅读(22) 评论(0) 推荐(0) 编辑
摘要: This is a "In Order" traversal problem, because the order of the result is a in order or the tree. 1. The problem need to return the pointer to the sm 阅读全文
posted @ 2022-02-05 02:33 阳光明媚的菲越 阅读(22) 评论(0) 推荐(0) 编辑
摘要: 如果你碰到排列组合的题,就想想是否可以用backtracking做,然后把模版记住: private List<List<Integer>> res = new ArrayList<>(); public List<List<Integer>> subsets(int[] nums) { backt 阅读全文
posted @ 2022-02-04 12:37 阳光明媚的菲越 阅读(27) 评论(0) 推荐(0) 编辑
摘要: Solution 1: Union-Found private int[] root; private int count; public boolean validTree(int n, int[][] edges) { count = n; if(edges.length!=n-1) retur 阅读全文
posted @ 2022-02-04 11:55 阳光明媚的菲越 阅读(24) 评论(0) 推荐(0) 编辑
摘要: I have originally write a BFS solution for this problem, but it seems too difficlut. And then I read other's code, found that solution is much easier. 阅读全文
posted @ 2022-02-04 10:15 阳光明媚的菲越 阅读(16) 评论(0) 推荐(0) 编辑
上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 17 下一页