feat: 2025-10-24打卡
This commit is contained in:
31
206.reverse-linked-list.java
Normal file
31
206.reverse-linked-list.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* @lc app=leetcode id=206 lang=java
|
||||
*
|
||||
* [206] Reverse Linked List
|
||||
*/
|
||||
|
||||
// @lc code=start
|
||||
/**
|
||||
* Definition for singly-linked list.
|
||||
* public class ListNode {
|
||||
* int val;
|
||||
* ListNode next;
|
||||
* ListNode() {}
|
||||
* ListNode(int val) { this.val = val; }
|
||||
* ListNode(int val, ListNode next) { this.val = val; this.next = next; }
|
||||
* }
|
||||
*/
|
||||
class Solution {
|
||||
public ListNode reverseList(ListNode head) {
|
||||
ListNode prev = null, cur = head, t;
|
||||
while(cur != null) {
|
||||
t = cur.next;
|
||||
cur.next = prev;
|
||||
prev = cur;
|
||||
cur = t;
|
||||
}
|
||||
return prev;
|
||||
}
|
||||
}
|
||||
// @lc code=end
|
||||
|
||||
Reference in New Issue
Block a user