This file contains hidden or 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
//input: expression string, there may be multiple spaces | |
//return: reverse polish notation string with one space between each element | |
class Solution { | |
public String convertToReversePolish(String exp) { | |
if (exp == null) | |
return null; | |
String res = ""; | |
int len = exp.length(); | |
Stack<Character> operator = new Stack<Character>(); | |
Stack<String> reversePolish = new Stack<String>(); |
This file contains hidden or 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 undirected graph. | |
* class UndirectedGraphNode { | |
* int label; | |
* List<UndirectedGraphNode> neighbors; | |
* UndirectedGraphNode(int x) { label = x; neighbors = new ArrayList<UndirectedGraphNode>(); } | |
* }; | |
*/ | |
public class Solution { | |
public UndirectedGraphNode cloneGraph(UndirectedGraphNode node) { |
This file contains hidden or 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 canCompleteCircuit(int[] gas, int[] cost) { | |
if (gas == null || cost== null) | |
return -1; | |
int diff = 0; | |
int len = gas.length; | |
int start = 0; | |
for (int i = 0; i <= 2 * len - 1; i++) { | |
diff += (gas[i % len] - cost[i % len]); | |
if (diff < 0) { |
This file contains hidden or 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 canJump(int[] A) { | |
if (A == null) | |
return false; | |
int len = A.length; | |
if (len == 0) | |
return false; | |
int rightBound = A[0]; | |
int i = 0; | |
while (i <= rightBound) { |
This file contains hidden or 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 canJump(int[] A) { | |
if (A == null) | |
return false; | |
int len = A.length; | |
if (len == 0) | |
return false; | |
if (len == 1) | |
return true; | |
int gap = 1; |
This file contains hidden or 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 jump(int[] A) { | |
if (A == null) | |
return -1; | |
int len = A.length; | |
if (len == 0) | |
return -1; | |
if (len == 1) | |
return 0; | |
int rightBound = A[0]; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 { |