原创 Convert Sorted Array(List) to Binary Search Tree

Convert Sorted Array to Binary Search Tree Given an array where elements are sorted in ascending order, convert it

原创 2sum 3sum 4sum 各種sum

Two Sum Given an array of integers, find two numbers such that they add up to a specific target number. The functio

原创 Pow(x, n)

Pow(x, n) Implement pow(x, n). 題目:實現求冪函數。 分析:基本算法比較簡單,遞歸二分,5^4 = 5^2 * 5^2  主要在於對一些特殊情況的處理: x爲0,double判斷是否爲0不能直接用==

原创 Word Ladder

Word Ladder Given two words (start and end), and a dictionary, find the length of shortest transformation sequence

原创 Validate Binary Search Tree

Validate Binary Search Tree Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST

原创 Implement strStr()

Implement strStr() Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if

原创 Sqrt(x)

Sqrt(x) Implement int sqrt(int x). Compute and return the square root of x. 題目:求平方根 分析:完全沒思路,好像可以用二分法,向中間夾逼,但不過。 求根

原创 Flatten Binary Tree to Linked List

Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / \ 2 5

原创 Reverse Linked List II

Reverse Linked List II   Reverse a linked list from position m to n. Do it in-place and in one-pass. For example:

原创 Climbing Stairs

Climbing Stairs You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb

原创 Sum Root to Leaf Numbers

Sum Root to Leaf Numbers Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represen

原创 各種Parentheses

Valid Parentheses Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the i

原创 Unique Binary Search Trees I & II

Unique Binary Search Trees Given n, how many structurally unique BST's (binary search trees) that store values 1...

原创 Anagrams

Anagrams Given an array of strings, return all groups of strings that are anagrams. Note: All inputs will be in low

原创 Scramble String

Scramble String Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substri