上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 36 下一页
摘要: 递归 class Solution { public ListNode mergeKLists(ListNode[] lists){ return mergeKLists(lists, 0); } public ListNode mergeKLists(ListNode[] lists, int l 阅读全文
posted @ 2021-12-24 16:42 振袖秋枫问红叶 阅读(29) 评论(0) 推荐(0)
摘要: 优先队列+Map import java.util.Comparator; import java.util.HashMap; import java.util.PriorityQueue; class Solution { public int[] topKFrequent(int[] nums, 阅读全文
posted @ 2021-12-24 10:23 振袖秋枫问红叶 阅读(42) 评论(0) 推荐(0)
摘要: 广度优先搜索+队列 class Solution { public List<Integer> rightSideView(TreeNode root) { List<Integer> list = new LinkedList<>(); if (root == null){ return list 阅读全文
posted @ 2021-12-23 15:07 振袖秋枫问红叶 阅读(29) 评论(0) 推荐(0)
摘要: 广度优先搜索+队列 class Solution { public List<List<Integer>> zigzagLevelOrder(TreeNode root) { List<List<Integer>> list = new LinkedList<>(); if (root == nul 阅读全文
posted @ 2021-12-23 11:44 振袖秋枫问红叶 阅读(35) 评论(0) 推荐(0)
摘要: 广度优先搜索 class Solution { public List<List<Integer>> levelOrderBottom(TreeNode root) { List<List<Integer>> list = new ArrayList<>(); if (root == null){ 阅读全文
posted @ 2021-12-23 11:10 振袖秋枫问红叶 阅读(23) 评论(0) 推荐(0)
摘要: 广度优先搜索+队列 import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Queue; class Solution { public List<List<In 阅读全文
posted @ 2021-12-23 10:55 振袖秋枫问红叶 阅读(32) 评论(0) 推荐(0)
摘要: 栈 import java.util.Iterator; import java.util.List; import java.util.Stack; class NestedIterator implements Iterator<Integer> { Stack<NestedInteger> s 阅读全文
posted @ 2021-12-21 16:44 振袖秋枫问红叶 阅读(38) 评论(0) 推荐(0)
摘要: 栈 import java.util.Stack; class Solution { public String simplifyPath(String path) { /** * 如果有连续的"//"会变成空字符串,需要额外判断 */ String[] newString = path.split 阅读全文
posted @ 2021-12-20 11:26 振袖秋枫问红叶 阅读(41) 评论(0) 推荐(1)
摘要: 栈 import java.util.Stack; class Solution { public int evalRPN(String[] tokens) { /** * 逆波兰表达式 * 遇到数字压入栈,遇到算符就弹出最后两个数进行计算,将结果再压入栈 * 最后剩下一个数字,就是最终结果 */ 阅读全文
posted @ 2021-12-20 10:51 振袖秋枫问红叶 阅读(38) 评论(0) 推荐(1)
摘要: 双指针法 class Solution { public boolean isPalindrome(ListNode head) { ListNode dummyHead = new ListNode(0, head); ListNode slow = dummyHead; ListNode fas 阅读全文
posted @ 2021-12-19 18:29 振袖秋枫问红叶 阅读(32) 评论(0) 推荐(0)
上一页 1 ··· 15 16 17 18 19 20 21 22 23 ··· 36 下一页