原创 string to integer (atoi)
Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a c
原创 [LeetCode] Populating Next RIght Pointer in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tree could be any binary
原创 [LeetCode] Regular Expression matching
'.' Matches any single character. '*' Matches zero or more of the preceding element. The matching should cover the en
原创 [LeetCode] Single Number II
Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algor
原创 [LeetCode] Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with
原创 [LeetCode] CLone Graph
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's undirected gra
原创 [LeetCode] Binary Tree Zigzag level order traversal
Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then righ
原创 [LeetCode] Convert Sorted List to Binary Search Tree
/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNod
原创 [LeetCode] Recover Binary Search Tree
wo elements of a binary search tree (BST) are swapped by mistake. Recover the tree without changing its structure. No
原创 [LeetCode] Palindrom Partitioning II
Given a string s, partition s such that every substring of the partition is a palindrome. Return the minimum cuts ne
原创 [LeetCode]Median of Two Sorted Arrays
There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall
原创 [LeetCode] Surrounded Regions
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured by flipping al
原创 [LeetCode] Roman to Integer and Integer to Roman
羅馬數字共有7個,即I(1)、V(5)、X(10)、L(50)、C(100)、D(500)和M(1000)。按照下述的規則可以表示任意正整數。需要注意的是羅馬數字中沒有“0”,與進位制無關。一般認為羅馬數字只用來記數,而不作演算。 重
原创 [LeetCode] 2Sum, 3Sum, 4Sum, 3SUm closet
1. 2Sum: hash Table O(n*n) 2. 3Sum: 2Sum + 1 : O(n*n) for loop + 左右夾逼法:O(N*N) class Solution { public: vector<vecto
原创 [LeetCode] Scramble String
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.