Tag: Leetcode

1. Leetcode 11 Container With Most Water

Problem 11 Container With Most Water Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lines, which together with x-axis forms…

2. Leetcode 117 Populating Next Right Pointers in Each Node II

Problem 117 Populating Next Right Pointers in Each Node II Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tree could be any binary tree? Would your previous solution still work? Note: You may only use constant extra space. For example, Given the following…

3. Leetcode 75 Sort Colors

Problem 75 Sort Colors Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers 0, 1, and 2 to represent the color…

4. Leetcode 22 Generate Parentheses

Problem 22 Generate Parentheses Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. For example, given n = 3, a solution set is: "((()))", "(()())", "(())()", "()(())", "()()()" Many people say it is a easy problem, but I do not think so. As the idea is easy, but writing it…

5. Leetcode 21 Merge Two Sorted Lists

Problem 21 Merge Two Sorted Lists Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. Not a hard one. But I spend a lot of time on this, cause I misunderstand…