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 isBST { | |
public static void main(String[] args) { | |
int array[] = {30, 85, 5}; | |
Arrays.sort(array); | |
TreeNode node = TreeNode.createMinimalBST(array); | |
node.print(); | |
System.out.println(node.isBST()); | |
System.out.println(isValidBST(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 DoublePower { | |
public static void main(String[] args) { | |
double d = 5; | |
int n = 2; | |
System.out.println(pow(d,n)); | |
} | |
public static double pow(double d, int e) { | |
if(e == 0) return 1; // base case --> if exponent is zero, answer is 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
import java.util.Arrays; | |
public class Subsets { | |
public static void main(String[] args) { | |
String array[] = {"a", "b", "c"}; | |
System.out.println(Arrays.deepToString(subset(array))); | |
} | |
public static String[] subset(String array[]) { |
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
package com.shaaslam.tiny; | |
import java.time.LocalDateTime; | |
import java.time.ZoneId; | |
public class TinyUtils { | |
private static final String ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; | |
private static final long BASE = ALPHABET.length(); | |
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 static String rotate(String string, int k){ | |
if(string == null) return string; | |
if(string.length() < 2) return string; | |
if(k > string.length()) k = k % string.length(); | |
char[] result = new char[string.length()]; | |
for(int i = 0; i < k; i++){ | |
result[i] = string.charAt(string.length() - k + i); | |
} |
NewerOlder