Problem link: http://oj.leetcode.com/problems/word-break-ii/ This problem is some extension of the word break problem, so the solution is based on the discussion in Word Break. We also use DP to solve the problem. In this solution, A[i] is not a bool…
Problem link: http://oj.leetcode.com/problems/word-break/ We solve this problem using Dynamic Programming method. Let A[0..n-1] be a boolean array, where A[i]=True if and only if s[i..n-1] can be segmented into words. The recursive formula is: A[i] =…
Problem Link: http://oj.leetcode.com/problems/word-ladder-ii/ Basically, this problem is same to Word Ladder I, which uses a double-direction BFS. However, the difference is that we need to keep track of all paths during the double-direction BFS in o…
Problem Link: http://oj.leetcode.com/problems/word-ladder/ Two typical techniques are inspected in this problem: Hash Table. One hash set is the words dictionary where we can check if a word is in the dictionary in O(1) time. The other hash set is us…
Problem link: http://oj.leetcode.com/problems/reverse-words-in-a-string/ Given an input string, reverse the string word by word. For example, Given s = "the sky is blue", return "blue is sky the". LeetCode OJ supports Python now! The s…
Problem Link: http://oj.leetcode.com/problems/interleaving-string/ Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example, Given: s1 = "aabcc", s2 = "dbbca", When s3 = "aadbbcbcac", return t…
Problem Link: https://oj.leetcode.com/problems/recover-binary-search-tree/ We know that the inorder traversal of a binary search tree should be a sorted array. Therefore, we can compare each node with its previous node in the inorder to find the two…
Problem Link: http://oj.leetcode.com/problems/convert-sorted-list-to-binary-search-tree/ We design a auxilar function that convert a linked list to a node with following properties: The node is the mid-node of the linked list. The node's left child i…
Problem Link: http://oj.leetcode.com/problems/palindrome-partitioning/ We solve this problem using Dynamic Programming. The problem holds the property of optimal sub-strcuture. Assume S is a string that can be partitioned into palindromes w1, ..., wn…
Problem link: http://oj.leetcode.com/problems/linked-list-cycle-ii/ The solution has two step: Detecting the loop using faster/slower pointers. Finding the begining of the loop. After two pointers meet in step 1, keep one pointer and set anther to th…