原创 [Leetcode 123, Hard] Best Time to Buy and Sell Stock III
Problem: Design an algorithm to find the maximum profit. You may complete at most two transactions. Analysis: Solution
原创 [Leetcode 114, Medium] Flatten Binary Tree to Linked List
Problem: Given a binary tree, flatten it to a linked list in-place. For example, Given 1 / \
原创 [Leetcode 34, Medium] Search for a Range
Problem: Given a sorted array of integers, find the starting and ending position of a given target value. Your algor
原创 [leetcode 80, Medium] Remove Duplicates from Sorted Array II
Problem: Follow up for "Remove Duplicates": What if duplicates are allowed at most twice? For example, Given sorted
原创 Frequently used algorithms in Leetcode
1. Bianry search: (1) Sorted array, but not linked-list. BS requires backtracking.Double linked-list is also not a good
原创 [Leetcode 122, Medium] Best Time to Buy and Sell Stock II
Problem: Design an algorithm to find the maximum profit. You may complete as many transactions as you like (ie, buy on
原创 C++ outline and interview questions (1): Variable
1.1. Contents 1.1.1Variable: (1) Types: bool, char, int, long, longlong, float, double, long double. (2) Range: 1 byt
原创 [Leetcode 10, Hard] Regular Expression Matching
Problem: Implement regular expression matching with support for '.' and '*'. '.' Matches any single character. '*' Ma
原创 [Leetcode 30, Hard] Substring with Concatenation of All Words
Problem: You are given a string, s, and a list of words, words, that are all of the same length. Find all starting in
原创 [Leetcode 151, Medium] Reverse Words in a String
Problem: Given an input string, reverse the string word by word. For example, Given s = "the sky is blue", return "b
原创 [Leetcode 229, Medium] Majority Element II
Problem: Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm shoul
原创 [Leetcode 81, Medium] Search in Rotated Sorted Array II
Problem: Follow up for "Search in Rotated Sorted Array": What if duplicates are allowed? Would this affect the run-t
原创 [Leetcode 79, Medium] Word Search
Problem: Given a 2D board and a word, find if the word exists in the grid. The word can be constructed from letters
原创 [Leetcode 144, Medium] Binary Tree Preorder Traversal
Problem: Given a binary tree, return the preorder traversal of its nodes' values. For example: Given binary tree {1,
原创 [Leetcode 152, Medium] Maximum Product Subarray
Problem: Find the contiguous subarray within an array (containing at least one number) which has the largest product.