上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 14 下一页
摘要: 题目链接 二叉树特点左子树小于根节点根节点小于右子树 class Solution { public int kthSmallest(TreeNode root, int k) { //左子树节点个数 int leftN = findChild(root.left); //如果k等于左子树节点加一, 阅读全文
posted @ 2022-02-09 14:43 蹇爱黄 阅读(24) 评论(0) 推荐(0)
摘要: 题目链接 Set实现 Map实现 class Solution { public boolean containsDuplicate(int[] nums) { int len = nums.length; Map<Integer,Integer> map = new HashMap<>(len); 阅读全文
posted @ 2022-02-09 03:40 蹇爱黄 阅读(21) 评论(0) 推荐(0)
摘要: 题目链接 先用库函数试一下 快排:从两边往中间走,找个参照值,左边的大于参照值,右边的等于参照值时就交换这两个数。 class Solution { public int findKthLargest(int[] nums, int k) { qsort(nums, 0, nums.length - 阅读全文
posted @ 2022-02-09 02:57 蹇爱黄 阅读(30) 评论(0) 推荐(0)
摘要: 题目链接 真希望所有题都这么easy class Solution { public ListNode reverseList(ListNode head) { ListNode pre = null; ListNode cur = head; while(cur != null){ //temp保 阅读全文
posted @ 2022-02-09 02:07 蹇爱黄 阅读(23) 评论(0) 推荐(0)
摘要: 题目链接 既然个数大于一般那就先sort,再取中间吧 但是面试官可能会想要其答案 class Solution { public int majorityElement(int[] nums) { int count = 1,maj = nums[0]; for(int i = 1;i < nums 阅读全文
posted @ 2022-02-09 02:00 蹇爱黄 阅读(39) 评论(0) 推荐(0)
摘要: 题目链接 public class Solution { public ListNode getIntersectionNode(ListNode headA, ListNode headB) { if(headA == null || headB == null) return null; Lis 阅读全文
posted @ 2022-02-09 01:32 蹇爱黄 阅读(21) 评论(0) 推荐(0)
摘要: 这道题评论区的大佬真是各抒己见啊,我也不知道用栈来实现对不对,但是看到一个非常棒的用栈来实现的方法 class MinStack { private int min = Integer.MAX_VALUE; private Stack<Integer> stack; public MinStack( 阅读全文
posted @ 2022-02-09 01:13 蹇爱黄 阅读(22) 评论(0) 推荐(0)
摘要: 题目链接 递归排序三部曲:①快慢指针找中点;②递归调用mergeSort; ③合并两个链表 归并 class Solution { public ListNode sortList(ListNode head){ return mergeSort(head); } //归并排序 private Li 阅读全文
posted @ 2022-02-09 00:34 蹇爱黄 阅读(27) 评论(0) 推荐(0)
摘要: 感觉贼难啊 在Java里边比较简单 class LRUCache extends LinkedHashMap<Integer, Integer>{ private int capacity; public LRUCache(int capacity){ super(capacity,0.75F,tr 阅读全文
posted @ 2022-02-08 23:59 蹇爱黄 阅读(41) 评论(0) 推荐(0)
摘要: 题目链接 判断环的入口,需要先判断有没有环,在寻找环的入口,找入口时需要重新定义两个”指针“,一个指向头节点,一个指向当前fast,让他们前进速度相同,他们想入的点即为入口。 public class Solution { public ListNode detectCycle(ListNode h 阅读全文
posted @ 2022-02-08 17:12 蹇爱黄 阅读(41) 评论(0) 推荐(0)
上一页 1 ··· 3 4 5 6 7 8 9 10 11 ··· 14 下一页