Algo

算法练习LinkedList(七)--P82

link on JianShu

Remove Duplicates from Sorted List 2 Medium

Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.

Example 1:

Input: 1->2->3->3->4->4->5 Output: 1->2->5

Example 2:

Input: 1->1->1->2->3 Output: 2->3

昨天做得有点郁闷了。‘精准原子’操作的套路还是没有掌握,写半天没完成效果。按照O(n2)的思路实现就有点暴力了。

算法练习LinkedList(五)--P61

link on JianShu

Rotate List Medium

Given a linked list, rotate the list to the right by k places, where k is non-negative.

Example 1:

Input: 1->2->3->4->5->NULL, k = 2
Output: 4->5->1->2->3->NULL

Explanation:

rotate 1 steps to the right: 5->1->2->3->4->NULL
rotate 2 steps to the right: 4->5->1->2->3->NULL

Example 2:

Input: 0->1->2->NULL, k = 4
Output: 2->0->1->NULL

算法练习LinkedList(八)--P86

link on JianShu

86. Partition List Medium

Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.

You should preserve the original relative order of the nodes in each of the two partitions.

Example:

Input: head = 1->4->3->2->5->2, x = 3 Output: 1->2->2->4->3->5

梳理一下思路,应该很快可以写出来这样一个架子:

算法练习LinkedList(十一)--P109

link on JianShu

109. Convert Sorted List to Binary Search Tree

Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.

For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.

Example:
Given the sorted linked list: [-10,-3,0,5,9], One possible answer is: [0,-3,9,-10,null,5], which represents the following height balanced BST:

Algo issues

第一周题目

链表

简单:https://leetcode.com/problems/remove-duplicates-from-sorted-list/
简单:https://leetcode.com/problems/merge-two-sorted-lists
中等:https://leetcode.com/problems/swap-nodes-in-pairs/
中等:https://leetcode.com/problems/linked-list-cycle-ii
困难:https://leetcode.com/problems/reverse-nodes-in-k-group/