LeetCode – Remove Invalid Parentheses (Java)

Remove the minimum number of invalid parentheses in order to make the input string valid. Return all possible results. Note: The input string may contain letters other than the parentheses ( and ). Examples: “()())()” -> [“()()()”, “(())()”] “(a)())()” -> [“(a)()()”, “(a())()”] “)(” -> [“”] Java Solution This problem can be solve by using DFS. … Read more

LeetCode – Minimum Path Sum (Java)

Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Java Solution 1: Depth-First Search A native solution would be depth-first search. It’s time is too expensive and fails the online judgement. public int minPathSum(int[][] grid) … Read more

LeetCode – Basic Calculator II (Java)

Implement a basic calculator to evaluate a simple expression string. The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The integer division should truncate toward zero. You may assume that the given expression is always valid. Some examples: “3+2*2” = 7 Java Solution public int calculate(String s) { … Read more

LeetCode – PDF Update History (Java)

5/10/2016 1. Add about 20 more problems. 2. Optimize solutions for some old problems. 5/17/2016 1. Add 12 more problems. 2. Optimize solutions for some old problems. 3. Remove some naive solutions because they are too obvious and have no values. 8/1/2016 1. Add 30 more problems. 2. Optimize solutions for some old problems. 3. … Read more