增加淘宝群内容,修改部分文件组织
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
package 链表;
|
||||
|
||||
public class ListNode {
|
||||
int val;
|
||||
ListNode next;
|
||||
ListNode(int x) {
|
||||
val = x;
|
||||
}
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package 链表;
|
||||
|
||||
public class _141_环形链表 {
|
||||
|
||||
public boolean hasCycle(ListNode head) {
|
||||
if (head == null || head.next == null) return false;
|
||||
|
||||
ListNode slow = head;
|
||||
ListNode fast = head.next;
|
||||
while (fast != null && fast.next != null) {
|
||||
slow = slow.next;
|
||||
fast = fast.next.next;
|
||||
|
||||
if (slow == fast) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,29 @@
|
||||
package 链表;
|
||||
|
||||
public class _206_反转链表 {
|
||||
|
||||
public ListNode reverseList(ListNode head) {
|
||||
if (head == null || head.next == null) return head;
|
||||
|
||||
ListNode newHead = reverseList(head.next);
|
||||
head.next.next = head;
|
||||
head.next = null;
|
||||
return newHead;
|
||||
}
|
||||
|
||||
|
||||
public ListNode reverseList2(ListNode head) {
|
||||
if (head == null || head.next == null) return head;
|
||||
|
||||
ListNode newHead = null;
|
||||
while (head != null) {
|
||||
ListNode tmp = head.next;
|
||||
head.next = newHead;
|
||||
newHead = head;
|
||||
head = tmp;
|
||||
}
|
||||
|
||||
return newHead;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
package 链表;
|
||||
|
||||
/**
|
||||
* https://leetcode-cn.com/problems/delete-node-in-a-linked-list/
|
||||
* @author MJ Lee
|
||||
*
|
||||
*/
|
||||
public class _237_删除链表中的节点 {
|
||||
|
||||
public void deleteNode(ListNode node) {
|
||||
node.val = node.next.val;
|
||||
node.next = node.next.next;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user