Olivia Liu Blog

Hello world to all the glorious developers.

Leetcode 92. Reverse Linked List II

Lintcode 36. Reverse Linked List II

Description Reverse a linked list from position m to n. Do it in one-pass. Note: 1 ≤ m ≤ n ≤ length of list. Examples Input: 1->2->3->4->5->NULL, m = 2, n = 4 Output: 1->4->...

Leetcode 24. Swap Nodes in Pairs

Lintcode 451. Swap Nodes in Pairs

Description Given a linked list, swap every two adjacent nodes and return its head. You may not modify the values in the list’s nodes, only nodes itself may be changed. Examples Given 1->2-&...

Leetcode 206. Reverse Linked List

Lintcode 35. Reverse Linked List

Description Reverse a singly linked list. Examples Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL Answer The main idea of this problem is using two pointer...

Leetcode 142. Linked List Cycle II

Lintcode 103. Linked List Cycle II

Description Given a linked list, return the node where the cycle begins. If there is no cycle, return null. To represent a cycle in the given linked list, we use an integer pos which represents t...

Leetcode 141. Linked List Cycle

Lintcode 102. Linked List Cycle

Description Given a linked list, determine if it has a cycle in it. To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the linked li...

Leetcode 456. 132 Pattern

Lintcode 636. 132 Pattern

Description Given a sequence of n integers a1, a2, …, an, a 132 pattern is a subsequence ai, aj, ak such that i < j < k and ai < ak < aj. Design an algorithm that takes a list of n num...

Lintcode 611. Knight Shortest Path

Lintcode 611. Knight Shortest Path

Description Given a knight in a chessboard (a binary matrix with 0 as empty and 1 as barrier) with a source position, find the shortest path to a destination position, return the length of the rou...

Leetcode 210. Course Schedule II

Lintcode 616. Course Schedule II

Description There are a total of n courses you have to take, labeled from 0 to n-1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is exp...

Leetcode 207. Course Schedule

Lintcode 615. Course Schedule

Description There are a total of n courses you have to take, labeled from 0 to n-1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is exp...

Leetcode 102. Binary Tree Level Order Traversal

Lintcode 69. Binary Tree Level Order Traversal

Description Given a binary tree, return the level order traversal of its nodes’ values. (ie, from left to right, level by level). Answer Using queue to store current layer of binary tree. Traver...