class Solution { public: ListNode *swapPairs(ListNode *head) { if (head == NULL || head->next == NULL) return head; ListNode* newhead = head->next; ListNode* prev = NULL, *cur1 = head, *cur2 = head->next;; prev = cur1; cur1->next = cur2->next; cur2->next = cur1; while (prev->next != NULL && prev->next->next != NULL) { cur1 = prev->next; cur2 = cur1->next; prev->next = cur2; cur1->next = cur2->next; cur2->next = cur1; prev = cur1; } return newhead; } };
相关推荐
第四章 Leetcode 题解 1. Two Sum 2. Add Two Numbers 3. Longest Substring Without Repeating Characters 4. Median of Two Sorted Arrays...24. Swap Nodes in Pairs 25. Reverse Nodes in k-Group 26. Remove Dupli
LeetCode题目Largest Rectangle in Histogram 解答
leetcode 答案解析 golang解答
Swap Nodes in Pairs Spiral Matrix Path Sum II Copy List with Random Pointer Building H2O Fizz Buzz Multithreaded hard Merge k Sorted Lists Reverse Nodes in k-Group Trapping Rain Water
421 | [Maximum XOR of Two Numbers in an Array](https://leetcode.com/problems/maximum-xor-of-two-numbers-in-an-array/) | [C++](./C++/maximum-xor-of-two-numbers-in-an-array.cpp) [Python](./Python/...
leetcode下载 Algorithm 每日一题 && 天天进步一点点 题目来于 LeetCode,剑指offer,Coding Interview,ZOJ,POJ 等平台。 欢迎Coders对代码加以指正和提议!...Nodes in Pairs 练习: leetcode: 237. D
刷LeetCode刷LeetCode刷LeetCode刷LeetCode刷LeetCode
Leetcode Solutions in Rust, Advent of Code Solutions in Ru
algorithm templates and leetcode examples in Python3, you
leetcode 锈leetcode_in_rust 用 Rust 编写的 LeetCode 练习
LeetCode-Solutions-in-Swift.zip,swift 5中的leetcode解决方案
leetcode中文版
vs code LeetCode 插件
in Java 本项目是我对 上的问题的所有解答。LeetCode 是一个为准备 IT 面试的 OJ 平台,上面有非常丰富且高质量的问题。这里所有的解答都使用的 Java,并且你可以将本项目直接导入到 Eclipse 中。 每一道题都附带了 ...
大佬的leetcode刷题笔记(c++版本)
LeetCode 101_C++_算法_leetcode_leetcode101_leetcode101.zip
LeetCode 101_C++_算法_leetcode_leetcode101_leetcode101_源码.zip
24:swap-nodes-in-pairs 漂亮的递归解决方案 25: reverse-nodes-in-k-group: 解析 pre_for_next 到辅助函数 29:除以两个整数:溢出; 两反 31:下一个排列:再做一次(排序!) 32:最长有效(),使用栈,左推idx ...
LeetCode 解决VS Code中的LeetCode问题 英文文件| 文件 :exclamation_mark: 注意 :exclamation_mark: ...快速开始产品特点登入/登出 只需在LeetCode Explorer单击“ Sign in to LeetCode , LeetCode Explorer使用LeetC
100个leetCode详细解答