1 题目:

目前被墙,看不了。

2 思路:

比较简单,注意处理边界点就好

3 代码:

    public ListNode swapPairs(ListNode head) {
int temp;
if(head == null){
return null;
} ListNode h = head;
while(h != null){
ListNode node = h.next;
if(node!=null){
temp = h.val;
h.val = node.val;
node.val = temp;
h = h.next;
}
h = h.next;
} return head;
}

注意处理奇数个的时候。

[leetcode 24] Swap Nodes in k-Group的更多相关文章

  1. leetCode 24. Swap Nodes in Pairs (双数交换节点) 解题思路和方法

    Swap Nodes in Pairs  Given a linked list, swap every two adjacent nodes and return its head. For exa ...

  2. [LeetCode] 24. Swap Nodes in Pairs ☆☆☆(链表,相邻两节点交换)

    Swap Nodes in Pairs 描述 给定一个链表,两两交换其中相邻的节点,并返回交换后的链表. 示例: 给定 1->2->3->4, 你应该返回 2->1->4 ...

  3. [LeetCode] 24. Swap Nodes in Pairs 成对交换节点

    Given a linked list, swap every two adjacent nodes and return its head. You may not modify the value ...

  4. Java [leetcode 24]Swap Nodes in Pairs

    题目描述: Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1-& ...

  5. Leetcode 24——Swap Nodes in Pairs

    Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2-& ...

  6. LeetCode 24. Swap Nodes in Pairs 成对交换节点 C++/Java

    Given a linked list, swap every two adjacent nodes and return its head. You may not modify the value ...

  7. (链表 递归) leetcode 24. Swap Nodes in Pairs

    Given a linked list, swap every two adjacent nodes and return its head. You may not modify the value ...

  8. [leetcode]24. Swap Nodes in Pairs交换节点对

    Given a linked list, swap every two adjacent nodes and return its head. You may not modify the value ...

  9. LeetCode 24 Swap Nodes in Pairs (交换相邻节点)

    题目链接: https://leetcode.com/problems/swap-nodes-in-pairs/?tab=Description   Problem: 交换相邻的两个节点     如上 ...

  10. [LeetCode] 24. Swap Nodes in Pairs ☆

    Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2-& ...

随机推荐

  1. java.lang.OutOfMemoryError: Java heap space的解决方法

    windows->preferences->Java->Installed JRES->edit->Default VM Arguments添加-Xms256m -Xmx ...

  2. C# 对Access数据库操作的通用类

    (转载自博主Jerry很简单) //Access数据库-C# 操作类 代码using System;using System.Collections.Generic;using System.Linq ...

  3. Tire树入门专题

    POJ 3630Phone List 题目连接:http://poj.org/problem?id=3630 题意:问是否有号码是其他号码的前缀. #include<iostream> # ...

  4. git使用简单教程

    废话不多说,直接开始 1. 进入https://github.com/ 创建你的账号,然后开始创建一个你的仓库(基本概念请自行百度),比如jun. 2. 创建好仓库之后,下载git 3,设置git,就 ...

  5. My安卓知识3--多个activity之前共享数据的方法

    在网上搜这个问题的时候看到了有一篇文章说有五种方法: 1.基于消息的通信机制  Intent ---boudle ,extra 数据类型有限,比如遇到不可序列化的数据Bitmap,InputStrea ...

  6. 服务器Linux系统安全维护基础知识介绍

    事先规划好Linux操作系统的分区 Linux操作系统的分区规划跟微软操作系统的分区规划不同.后者分区规划对于其性能的影响很小.但是Linux操作系统的分区规划则不同,其对服务器的性能影响很大.其实我 ...

  7. link和import的区别

    1.link是xhtml标签,除了可以加载css外,还可以加载定义其他的事务:@import只属于css的范畴,只能加载css: 2.link引用CSS时,在页面载入时同时加载:@import需要页面 ...

  8. CentOS下搭建SVN

    1.安装svn yum -y install subversion 2.创建hydata目录 mkdir -p /var/svn/hydata 3.创建 m 目录 mkdir -p /var/svn/ ...

  9. SQL Server 大数据量分页建议方案

    简单的说就是这个 select top(20) * from( select *, rowid = row_number() over(order by xxx) from tb with(noloc ...

  10. Eclipse在线集成maven M2eclipse插件

    首先说下版本: Eclipse:3.6 Maven:3.3.1,若不知道如何在本地安装Maven,请参见我的另一篇文章:Window下安装Maven 废话少说,直接讲步骤就好: 1.打开eclipse ...