This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public boolean isValid(String s) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
if(s == null || s.length() == 0) | |
return true; | |
if(s.length() % 2 == 1) | |
return false; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
char symbols[] = {'M', 'D', 'C', 'L', 'X', 'V', 'I'}; | |
int values[] = {1000, 500, 100, 50, 10, 5, 1}; | |
public int romanToInt(String s) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
if(s.length() == 0) | |
return 0; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public ArrayList<ArrayList<Integer>> permute(int[] num) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
return permuteHelper(num, 0); | |
} | |
public ArrayList<ArrayList<Integer>> permuteHelper(int num[], int index){ | |
ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>(); | |
if(index == num.length - 1){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public String addBinary(String a, String b) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
int la = a.length(); | |
int lb = b.length(); | |
int max = Math.max(la, lb); | |
StringBuilder sum = new StringBuilder(""); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public ArrayList<String> anagrams(String[] strs) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
HashMap<String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>(); | |
ArrayList<String> result = new ArrayList<String>(); | |
if(strs.length < 2) | |
return result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for binary tree | |
* public class TreeNode { | |
* int val; | |
* TreeNode left; | |
* TreeNode right; | |
* TreeNode(int x) { val = x; } | |
* } | |
*/ | |
public class Solution { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public int threeSumClosest(int[] num, int target) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
Arrays.sort(num); | |
int diff = Integer.MAX_VALUE; | |
int closest = Integer.MAX_VALUE; | |
for(int i = 0; i < num.length - 2; i++){ | |
int k = i + 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Stack; | |
public class Solution { | |
public int largestRectangleArea(int[] height) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
int i = 0; | |
int max = 0; | |
Stack<Pair> stack = new Stack<Pair>(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public ArrayList<String> letterCombinations(String digits) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
ArrayList<String> result = new ArrayList<String>(); | |
char str[] = new char[digits.length()]; | |
helper(0, str, result, digits); | |
return result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Solution { | |
public int sqrt(int x) { | |
// Start typing your Java solution below | |
// DO NOT write main() function | |
long low = 0; | |
long high = x; | |
while(low <= high){ | |
long mid = low + (high - low) / 2; | |
long result = mid * mid; | |
if(result == x){ |
NewerOlder