125.Valid Palindrome

Given a string, determine if it is a palindrome, considering only alphanumeric characters and ignoring cases.

Read More

198.House Robber

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night.

Read More

238.Product of Array Except Self

Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].

Read More

Maximum Product Subarray

Find the contiguous subarray within an array (containing at least one number) which has the largest product.

Read More

056.Maximum Subarray

Find the contiguous subarray within an array (containing at least one number) which has the largest sum.

Read More

Gas Station

There are N gas stations along a circular route, where the amount of gas at station i is gas[i].

Read More

223.Rectangle Area

Find the total area covered by two rectilinear rectangles in a 2D plane.

Read More

155.Min Stack

Solutions with two stacks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
class MinStack {
Stack<Integer> nums = new Stack<Integer>();
Stack<Integer> min = new Stack<Integer>();

public void push(int x) {
nums.push(x);
if (!min.empty() && min.peek() < x){
min.push(min.peek());
}else{
min.push(x);
}
}

public void pop() {
if (!nums.empty() && !min.empty()){
nums.pop();
min.pop();
}
}

public int top() {
return nums.peek();
}

public int getMin() {
return min.peek();
}
}

Read More

232.Implement Queue Using Stacks

Implement the following operations of a queue using stacks.

Read More

225.Implement Stack Using Queue

Implement the following operations of a stack using queues.

Read More

162.Find Peak Element

A peak element is an element that is greater than its neighbors.

Read More

186.Reverse Words in a String II

Given an input string, reverse the string word by word. A word is defined as a sequence of non-space characters.

Read More

151.Reverse Words in a String

Given an input string, reverse the string word by word.

Read More

251.Flatten 2D Vector

Implement an iterator to flatten a 2d vector.

Read More

Paint House I

Paint House I

There are a row of n houses, each house can be painted with one of the three colors: red, blue or green. The cost of painting each house with a certain color is different. You have to paint all the houses such that no two adjacent houses have the same color.

Read More