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.io.File; | |
import java.io.FileInputStream; | |
import java.io.FileNotFoundException; | |
import java.io.InputStream; | |
import java.util.Arrays; | |
import java.util.HashSet; | |
import java.util.Scanner; | |
import java.util.Set; | |
import java.util.Stack; | |
import java.util.TreeSet; |
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
package findSubtreeEqualToBT; | |
import java.util.Stack; | |
public class Solution { | |
private static final class BtNode { | |
public BtNode left, right, parent; | |
public int val; |
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
package orderstats; | |
import java.util.Arrays; | |
public class Solution { | |
public static int ksmallest(int[] a, int k){ | |
return ksmallest(a, 0, a.length, k); | |
} | |
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
package stringpermutations; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class Solution { | |
public static int count = 0; | |
public static void perms(final String s) { |
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 static void rotate90(int[][] a){ | |
int n = a.length - 1; | |
for(int i = 0; i < a.length/2; i++){ | |
for(int j = i; j < a.length - i - 1; j++){ | |
int x = a[i][j]; | |
int y = a[j][n-i]; | |
int z = a[n-i][n-j]; | |
int w = a[n-j][i]; | |
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 static int findhead(int[] a){ | |
return findhead(a, 0, a.length); | |
} | |
private static int findhead(int[] a, int l, int h){ | |
if(a[0] > a[a.length - 1]){ | |
while(h > l){ | |
int m = (l+h)/2; | |
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 int maxProfit(int[] prices) { | |
if(prices.length < 2){ | |
return 0; | |
} | |
int sell = prices[prices.length - 1]; | |
int buy = Integer.MAX_VALUE; | |
int max = 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 static BstNode nextNode(BstNode n){ | |
if(n.parent == null){ | |
return n.right; | |
} | |
if(n.value > n.parent.value){ | |
if(n.right != null){ | |
return n.right; | |
}else{ | |
BstNode o = n; |
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
private static class EdgeNode{ | |
public EdgeNode next; | |
public int y; //edge node | |
public EdgeNode(int y){ | |
this.y = y; | |
} | |
} | |
private static class Graph{ |
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 BigFactorial { | |
private static int getdigits(int n){ | |
// Using array list for convenience of not having to implement re-sizable array | |
List<Integer> digits = new ArrayList<Integer>(); | |
//initialize our sum with n | |
int temp = n; | |
while(temp > 0){ | |
digits.add(0, temp % 10); |