训练计划 III (训练计划 III)

 

思路:

// @Title: 训练计划 III (训练计划 III)
// @Author: qisiii
// @Date: 2022-02-20 20:16:10
// @Runtime: 0 ms
// @Memory: 40.4 MB
// @comment: 
// @flag: 
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode(int x) { val = x; }
 * }
 */
class Solution {
    public ListNode reverseList(ListNode head) {
        ListNode pre=null;
        ListNode cur=head;
        while(cur!=null){
          ListNode temp =cur.next;
            cur.next=pre;
            pre=cur;
            cur=temp;
        }
        return pre;
    }
}
Licensed under CC BY-NC-SA 4.0
最后更新于 2024-10-18