25. Reverse Nodes in k-Group
2016-03-23 14:27
447 查看
ListNode* reverseKGroup(ListNode* head, int k) { vector<int> temp; while (head) { temp.push_back(head->val); head = head->next; } for (int i = k - 1; i < temp.size(); i += k) { int j = 0; while (j<k/2) { swap(temp[i-j], temp[i - k + 1+j]); j++; } } ListNode* res = new ListNode(0); ListNode** res1 = &res->next; for (auto i : temp) { res->next = new ListNode(i); res = res->next; } return *res1; }
相关文章推荐
- node js官网下载地址
- nodejs 异步协同问题
- gulp教程之gulp中文API
- gulp详细入门教程
- Node.js 的适用及不适用场合
- 'UserInfoBLL' node cannot be resolved for the specified context [MVC展示数据.Controllers.LoginController]问题解决
- Hadoop SecondaryNameNode
- meteor安装过慢 curl install.meteor.com | sh
- Win7下安装Node + WebMatrix
- [leetcode 24]Swap Nodes in Pairs-----成对翻转链表中的节点
- node.js study: cluster
- Swap Nodes in Pairs
- NodeJS + PhantomJS 抓取页面信息以及截图
- 快速搭建 Node.js 开发环境以及加速 npm
- Node.js文件操作二
- nodejs+express开发blog(2)
- node.js 异步I/O
- NodeJS - Error: The specified procedure could not be found
- Leetcode 19. Remove Nth Node From End of List
- node.js小工具--修改Xcode 'Create by'作者名称