本文主要是介绍定个小目标之每天刷LeetCode热题(7),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
今天这道题是道简单题,使用双指针进行迭代即可,画了下草图如下
代码如下
class Solution {public ListNode reverseList(ListNode head) {if (head == null || head.next == null) {return head;}ListNode p = head, q = head.next, temp = null;while (q != null) {p.next = temp;temp = p;p = q;q = q.next;}p.next = temp;return p;}
}
题目链接:题单 - 力扣(LeetCode)全球极客挚爱的技术成长平台
这篇关于定个小目标之每天刷LeetCode热题(7)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!