leetcode Submission Details
2015-07-01 16:21
387 查看
代码:
#include<iostream> #include<vector> using namespace std; struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {} }; ListNode* rotateRight(ListNode* head, int k) { if (head == NULL) return head; ListNode * p = head; int i = 1; while (p->next != NULL) { p = p->next; i++; } ListNode * tail = p; int L = i; cout << "L = " << L << endl; k = L - k%L; cout << "K = " << k << endl; if (k == L) return head; i = 1; p = head; while (i != k) { p = p->next; i++; } cout << "p ="<<p->val << endl; ListNode *newHead = p->next; p->next = NULL; tail->next = head; return newHead; } int main() { ListNode * head = new ListNode(1); ListNode *p = head; for (int i = 2; i <= 5; i++) { p->next = new ListNode(i); p = p->next; } p = NULL; for (ListNode * temp = head; temp != NULL; temp = temp->next) cout << temp->val << endl; ListNode * newHead = rotateRight(head, 2); cout << "-----------------------------------------" << endl; for (ListNode * temp = newHead; temp != NULL; temp = temp->next) cout << temp->val << endl; }
相关文章推荐
- Obtain Diesel engine Designer watches can be bought in the many most up-to-date styles and designs
- svn:cleanup failed previous operation has not finished; run cleanup if it was interrupted
- svn:cleanup failed previous operation has not finished; run cleanup if it was interrupted
- windows安装Apache,注册服务出现“(OS 5)拒绝访问。 : AH00369: Failed to open the WinNT service manager..."错误 [转]
- xcode6错误提醒:Failed to code sign "某某Tests".
- svn cleanup failed-previous operation has not finished; run cleanup if it was interrupted
- Matrix-chain product 矩阵链乘积
- main函数总结
- 扎克伯格:我们为何要研究人工智能和虚拟现实
- 扎克伯格:我们为什么要研究人工智能与虚拟现实?
- 03-树3. Tree Traversals Again (25)
- Leetcode_num13_Climbing Stairs
- centos7解决django.db.utils.OperationalError: FATAL: Peer authentication failed for user "postgres"
- lucene报错Lock obtain timed out:
- mfcs90d.lib(xxx.obj) : error LNK2005: DllMain@12 already defined in MSVCRTD.lib(xxx.obj)
- LeetCode_70---Climbing Stairs
- Socket通信之BIO(同步阻塞IO)、PAIO(伪异步阻塞IO)、NIO(异步非阻塞IO)、AIO(异步非阻塞IO)、netty5之IO
- pycurl提示load dll failed 找不到注册程序
- leetcode_Contains Duplicate
- 终于完成几个淘宝采集相关产品(http://www.9zhai.net/)