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
def remove(text): | |
for letter in text: | |
if letter.lower() in ['a','e','i','o','u']: | |
text = text.replace(letter, '') | |
return text | |
import re | |
def anti_vowels(text): |
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 int[] topK(int[] arr, int k) { | |
// default is ascending order | |
Queue<Integer> queue = new PriorityQueue<Integer>(); | |
int i = 0; | |
for (; i < k; i++) { | |
queue.add(arr[i]); | |
} | |
for (; i < arr.length; i++) { | |
queue.add(arr[i]); | |
queue.poll(); // Retrieves and removes the head of this queue, which is smallest element in the queue |
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
// Find the minimum path sum (from root to leaf) | |
public static int minPathSum(TreeNode root) { | |
if(root == null) return 0; | |
int sum = root.val; | |
int leftSum = minPathSum(root.left); | |
int rightSum = minPathSum(root.right); | |
if(leftSum < rightSum){ | |
sum += leftSum; |
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 boolean isFibo(long n){ | |
return isPerfectSquare(5*n*n+4) || isPerfectSquare(5*n*n-4); | |
} | |
public static boolean isPerfectSquare(double a){ | |
int s = (int) Math.sqrt(a); | |
return s*s == a; | |
} |
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 boolean validBST(int[] arr){ | |
int lowerbound = Integer.MIN_VALUE; | |
Stack<Integer> stack = new Stack<Integer>(); | |
for(int i : arr){ | |
if(i < lowerbound) return false; | |
while(!stack.isEmpty() && i > stack.peek()){ | |
lowerbound = stack.pop(); | |
} | |
stack.push(i); |