末日搭车指南
面向人生编程

导航

 
上一页 1 2 3 4 5 6 7 ··· 10 下一页

2020年10月1日

摘要: (1)前序遍历:前序遍历首先访问根节点,然后遍历左子树,最后遍历右子树 (2)中序遍历:中序遍历是先遍历左子树,然后访问根节点,然后遍历右子树 (3)后序遍历:后序遍历是先遍历左子树,然后遍历右子树,最后访问树的根节点。 二 树的存储结构 public class TreeNode { int va 阅读全文
posted @ 2020-10-01 21:44 末日搭车指南 阅读(134) 评论(0) 推荐(0)
 
摘要: (1)对数组元素进行替换--Arrays类的静态方法fill() 在原数组上,不建立新的内存 (2)对数组进行排序 Arrays类就静态sort()方法 可对任意类型数组,升序排序,在原数组上,不建立新的内存 Arrays.sort(object); //object为要被排序的数组 数字在字母之前 阅读全文
posted @ 2020-10-01 19:39 末日搭车指南 阅读(114) 评论(0) 推荐(0)
 

2020年8月19日

摘要: 我的方法:迭代 class Solution { public ListNode reverseList(ListNode head) { if(head==null) return null; if(head.next==null) return head; ListNode pos=head.n 阅读全文
posted @ 2020-08-19 08:13 末日搭车指南 阅读(147) 评论(0) 推荐(0)
 

2020年8月18日

摘要: // 初始化 快指针和慢指针 ListNode slow = head; ListNode fast = head; /** * Change this condition to fit specific problem. * 在这里避免空指针错误 **/ while (slow != null & 阅读全文
posted @ 2020-08-18 12:55 末日搭车指南 阅读(179) 评论(0) 推荐(0)
 
摘要: 我的代码:测试用例【1,2】2, 时会报错,无法不能删除第一个指针 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { v 阅读全文
posted @ 2020-08-18 12:44 末日搭车指南 阅读(174) 评论(0) 推荐(0)
 

2020年8月17日

摘要: 方法一: 暴力法 遍历A中每个节点,看看B中有没有 public class Solution { public ListNode getIntersectionNode(ListNode headA, ListNode headB) { if (headA==null||headB==null) 阅读全文
posted @ 2020-08-17 07:44 末日搭车指南 阅读(96) 评论(0) 推荐(0)
 
摘要: 第一阶段:判断是否有环 第二阶段:判断入环口在哪里 /** * 双指针 时间复杂度 O(n) 空间复杂度 O(1) * * 先用双指针法判断链表是否有环,若有则返回第一次相遇的节点 * * 第一次相遇时,假设【慢指针】 slow 走了 k 步,那么快指针 fast 一定走了 2k 步, * 也就是说 阅读全文
posted @ 2020-08-17 06:15 末日搭车指南 阅读(408) 评论(0) 推荐(0)
 
摘要: 如果列表中不存在环,最终快指针将会最先到达尾部,此时我们可以返回 false public boolean hasCycle(ListNode head) { if (head == null || head.next == null) { return false; } ListNode slow 阅读全文
posted @ 2020-08-17 04:34 末日搭车指南 阅读(182) 评论(0) 推荐(0)
 
摘要: public boolean hasCycle(ListNode head) { Set<ListNode> nodesSeen = new HashSet<>(); while (head != null) { if (nodesSeen.contains(head)) { return true 阅读全文
posted @ 2020-08-17 03:52 末日搭车指南 阅读(142) 评论(0) 推荐(0)
 

2020年8月14日

摘要: 通过比较 index 和 size - index 的大小判断从头开始较快还是从尾巴开始较快 public class ListNode { int val; ListNode next; ListNode prev; ListNode(int x) { val = x; } //这个只是用来初始化 阅读全文
posted @ 2020-08-14 12:12 末日搭车指南 阅读(114) 评论(0) 推荐(0)
 
上一页 1 2 3 4 5 6 7 ··· 10 下一页