Leetcode 328. Odd Even Linked List (Medium) (cpp)
来源:互联网 发布:keeper是什么软件 编辑:程序博客网 时间:2024/04/26 06:05
Leetcode 328. Odd Even Linked List (Medium) (cpp)
Tag: Linked List
Difficulty: Medium
/*328. Odd Even Linked List (Medium)Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do it in place. The program should run in O(1) space complexity and O(nodes) time complexity.Example:Given 1->2->3->4->5->NULL,return 1->3->5->2->4->NULL.Note:The relative order inside both the even and odd groups should remain as it was in the input. The first node is considered odd, the second node even and so on ...*//** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* oddEvenList(ListNode* head) { if (head == NULL || head -> next == NULL) { return head; } ListNode *o = head, *eh = head -> next, *e = head -> next; while (o -> next && e -> next) { o -> next = e -> next; o = e -> next; e -> next = o -> next; e = o -> next; } o -> next = eh; return head; }};
0 0
- Leetcode 328. Odd Even Linked List (Medium) (cpp)
- [leetcode]328. Odd Even Linked List [medium]
- LeetCode 328. Odd Even Linked List (Medium)
- 328. Odd Even Linked List #Medium
- 328. Odd Even Linked List leetcode(list)
- LeetCode—328. Odd Even Linked List
- LeetCode 328. Odd Even Linked List Java
- Leetcode 328. Odd Even Linked List
- <LeetCode><Easy> 328. Odd Even Linked List
- [leetcode] - 328. Odd Even Linked List
- <LeetCode OJ> 328. Odd Even Linked List
- 328. Odd Even Linked List LeetCode
- leetCode 328. Odd Even Linked List
- Leetcode: 328. Odd Even Linked List(JAVA)
- LeetCode--328. Odd Even Linked List
- LeetCode 328. Odd Even Linked List
- LeetCode 328. Odd Even Linked List
- [LeetCode]328. Odd Even Linked List
- 牛顿法(newton's method)求解函数极值
- tomcat虚拟路径配置
- 剑指offer-求1+2+3+…+n
- .DS_Store 文件怎么彻底删除?
- iOS面向切面编程
- Leetcode 328. Odd Even Linked List (Medium) (cpp)
- 如何释放含有NSTimer的UITableViewCell(SubView)
- zepto tap事件的一个bug
- 自定义View 实现抽屉式侧滑菜单 MySlidingMenu
- 2809: [Apio2012]dispatching
- 3年职业规划
- Ecplise 配置Python,Jython开发环境
- 在ubuntu系统环境下搭建java环境,以及各种软件的安装
- JNDI全面总结