原创 leetcode #130 in cpp
Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured by flipping al
原创 *leetcode #128 in cpp
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. For example, Give
原创 *leetcode #115 in cpp
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a
原创 leetcode #4 in cpp
Code: class Solution { public: string longestPalindrome(string s) { int n = s.length(); bool dp[n
原创 leetcode #129 in cpp
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number. An example is
原创 *leetcode #135 in cpp
There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these chil
原创 *leetcode #124 in cpp
Given a binary tree, find the maximum path sum. For this problem, a path is defined as any sequence of nodes from so
原创 *leetcode #123 in cpp
Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find
原创 leetcode #118 in cpp
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Return [ [1],
原创 leetcode #116 in cpp
Solution: perform BFS to traverse the tree level by level using a queue. For each level, pop current front node, link
原创 leetcode #114 in cpp
Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / \ 2 5
原创 leetcode #122 in cpp
Say you have an array for which the ith element is the price of a given stock on day i. Design an algorithm to find
原创 leetcode #117 in cpp
Solution: Similar to #116. Only difference is that we push left or right into queue when left/right is not NULL. Code:
原创 leetcode #121 in cpp
Solution: We should look for increasing order in the list. Suppose we have an increasing list, then the maximum profit
原创 leetcode #127 in cpp
Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation seq