LeetCode OJ--Reverse Linked List II
http://oj.leetcode.com/problems/reverse-linked-list-ii/
链表的操作
#include <iostream>
using namespace std; struct ListNode {
int val;
ListNode *next;
ListNode(int x) : val(x), next(NULL) {}
}; class Solution {
public:
ListNode *reverseBetween(ListNode *head, int m, int n) {
ListNode dummy(-);
dummy.next = head; ListNode *prev = &dummy;
for(int i = ;i<m-;++i)
{
prev = prev->next;
}
ListNode* const head2 = prev; prev = head2->next;
ListNode *cur = prev->next;
for(int i = m;i<n;++i)
{
prev->next = cur->next;
cur->next = head2->next;
head2->next = cur;
cur = prev->next;
}
return dummy.next;
}
}; int main()
{
ListNode *n1 = new ListNode();
ListNode *n2 = new ListNode();
ListNode *n3 = new ListNode();
ListNode *n4 = new ListNode();
ListNode *n5 = new ListNode();
n1->next = n2;
n2->next = n3;
n3->next = n4;
n4->next = n5;
ListNode *ans;
Solution myS;
ans = myS.reverseBetween(n1,,);
return ;
}
LeetCode OJ--Reverse Linked List II的更多相关文章
- 【leetcode】Reverse Linked List II
		
Reverse Linked List II Reverse a linked list from position m to n. Do it in-place and in one-pass. F ...
 - leetcode -day30  Reverse Linked List II
		
1.  Reverse Linked List II Reverse a linked list from position m to n. Do it in-place and in one- ...
 - [LeetCode] 92. Reverse Linked List II 反向链表II
		
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...
 - Java for LeetCode 092 Reverse Linked List II
		
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1-> ...
 - [LeetCode] 92. Reverse Linked List II 倒置链表之二
		
Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Exa ...
 - leetcode 【 Reverse Linked List II  】 python 实现
		
题目: Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1- ...
 - 【leetcode】Reverse Linked List II (middle)
		
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...
 - leetcode 92  Reverse Linked List II ----- java
		
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...
 - leetcode:Reverse Linked List II
		
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:Given 1-> ...
 - LeetCode 92. Reverse Linked List II倒置链表2 C++
		
Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Exa ...
 
随机推荐
- 结合浅层高层特征的paper总结
			
1.ION:在conv3.conv4.conv5和context features上分别进行roi_pooling,在channel那一维进行concat 2.Hypernet:在较浅层max_poo ...
 - Gersgorin 圆盘
			
将学习到什么 好多. Gersgorin 圆盘定理 对任何 \(A \in M_n\),我们总可以记 \(A=D+B\),其中 \(D=\mathrm{diag}(a_{11},\cdots, ...
 - poi导出word模板项目实例(一个文件)
			
在页面上填写值,然后导出到word模板中,并把页面上的值带到模板中,也就是导出word文档,提前有word 的模板形式, 1.jsp 页面 <table class="formTa ...
 - Bootstrap历练实例:输入框组的大小
			
<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content=&q ...
 - 661. Image Smoother@python
			
Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother t ...
 - centos中python2替换为python3,并解决yum出错
			
这里采用安装python3.6版本. 安装python3.6可能使用的依赖 yum install openssl-devel bzip2-devel expat-devel gdbm-devel r ...
 - 利用Vert.x构建简单的API 服务、分布式服务
			
目前已经使用Vertx已经一年多了,虽然没有太多的造诣,但也已在项目中推广了下:从最初的vertx搭建web服务,到项目上线运营,还算比较稳定.再到后来尝试搭建基于vertx的分布式服务,一路下来也积 ...
 - SQLAlchemy常用操作
			
Models 只是配置和使用比较简单,因为他是Django自带的ORM框架,也正是因为是Django原生的,所以兼容性远远不如SQLAlchemy 真正算得上全面的ORM框架必然是我们的SQLAlch ...
 - xfce-OpenVAS
			
OpenVAS开源风险评估系统部署方案 OpenVAS,即开放式漏洞评估系统,是一个用于评估目标漏洞的杰出框架.功能十分强大,最重要的是,它是“开源”的——就是免费的意思啦- 它与著名的Nessu ...
 - swift final关键字、?、!可选与非可选符
			
?符号: 可选型 在初始化时可以赋值为nil !符号: 隐形可选型 类型值不能为nil,如果解包后的可选类型为nil会报运行时错误,主要用在一个变量/常量在定义瞬间完成之后值一定会存在的情况.这主要 ...