leetcode日志:解题参考引用

来源:互联网 发布:vivo软件开发待遇 编辑:程序博客网 时间:2024/06/06 10:59

283. Move Zeroes

给定一个数组nums,编写函数将数组内所有0元素移至数组末尾,并保持非0元素相对顺序不变。例如,给定nums = [0, 1, 0, 3, 12],调用函数完毕后, nums应该是 [1, 3, 12, 0, 0]。

要点:双指针

题目:https://leetcode.com/problems/move-zeroes/

解答:http://www.2cto.com/kf/201512/455439.html

-------------------------------------------------------------------------------------------------------------------

328. Odd Even Linked List

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 ...

要点:第一个节点被默认为奇数,第二个为偶数,奇偶交错排列,所以分别,取得第一个和第二个节点的指针,当作奇数和偶数的链表头,然后将每个奇数放入奇数链表,偶数放入偶数链表,最后连起来。

解答:http://blog.csdn.net/guicaisa/article/details/50557475

-------------------------------------------------------------------------------------------------------------------

83. Remove Duplicates from Sorted List

Given a sorted linked list, delete all duplicates such that each element appear only once.

For example,
Given 1->1->2, return 1->2.
Given 1->1->2->3->3, return 1->2->3.

要点:注意是sorted,因此可以使用双指针,指针index和指针current,如果current与index相同那么进行跳过操作,之后current++,index++;如果不同,那么久不执行跳过操作,index不动,但current需要增加。

解题之一:http://blog.csdn.net/feliciafay/article/details/18072359

---------------------------------------------------------------------------------------------------------------------------------------------

107. Binary Tree Level Order Traversal II

http://www.cnblogs.com/Azhu/p/4132676.html

http://www.2cto.com/kf/201601/487081.html

http://www.acmerblog.com/leetcode-solution-binary-tree-zigzag-level-order-traversal-6239.html

http://blog.csdn.net/sunao2002002/article/details/46280539



0 1
原创粉丝点击