Skip to content

Instantly share code, notes, and snippets.

//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>();
/**
* 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) {
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) {
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) {
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;
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];
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
/**
* Definition for binary tree
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {