213.House Robber II

Note: This is an extension of House Robber.

Read More

124.Binary Tree Maximum Path Sum

Given a binary tree, find the maximum path sum.

Read More

204.Count Primes

Description:

Read More

117.Populating Next Right Pointers in Each Node II

Follow up for problem “Populating Next Right Pointers in Each Node”.

Read More

116.Populating Next Right Pointers in Each Node

Given a binary tree

Read More

381.Insert Delete GetRandom O(1) - Duplicates Allowed

Design a data structure that supports all following operations in average O(1) time.

Read More

380.Insert Delete GetRandom O(1)

Design a data structure that supports all following operations in average O(1) time.

Read More

215.Kth Largest Element in an Array

Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.

Read More

059.Spiral Matrix II

Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.

Read More

054.Spiral Matrix

Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.

Read More

112.Path Sum

Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.

Read More

101.Symmetric Tree

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).

Read More

168.Excel Sheet Column Title

Given a positive integer, return its corresponding column title as appear in an Excel sheet.

Read More

075.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.

Read More

121.Best Time to Buy and Sell Stock

O(n) time O(1) space one pass solution

1
2
3
4
5
6
7
8
9
10
11
12
13
public class Solution {
public int maxProfit(int[] prices) {
int min = Integer.MAX_VALUE, profit = 0;
for (int i = 0; i < prices.length; i++) {
if (prices[i] < min) {
min = prices[i];
} else {
profit = Math.max(profit, prices[i] - min);
}
}
return profit;
}
}

Read More