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
#__author__ James Porcelli | |
""" | |
Insertion sort, O(n) for n = 5 | |
""" | |
def insert_sort(s): | |
for i in range(1, len(s)): | |
j = i | |
while j > 0 and s[j - 1] > s[j]: |
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 boolean isPalindrome(int x) { | |
if(x < 0){ | |
return false; | |
} | |
int temp = x; | |
//element in position[0] is first digit | |
List<Integer> digits = new ArrayList<Integer>(); | |
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 ListNode addTwoNumbers(ListNode l1, ListNode l2) { | |
ListNode head = null; | |
ListNode traveler = null; | |
int remainder = 0; | |
while(l1 != null || l2 != null){ | |
int x = l1.val + l2.val + remainder; | |
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 boolean isBalanced(TreeNode root) { | |
int left, right; | |
if(root == null){ | |
return true; | |
} | |
if(root.left != null){ | |
if(isBalanced(root.left)){ |
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 String addBinary(String a, String b) { | |
a = new StringBuilder(a).reverse().toString(); | |
b = new StringBuilder(b).reverse().toString(); | |
StringBuffer buf = new StringBuffer(100); | |
int size = 0; | |
int remainder = 0; | |
int i = getVal(a, size); | |
int j = getVal(b, size); |
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 boolean isBalanced(TreeNode root) { | |
if(getHeight(root) == -1){ | |
return false; | |
}else{ | |
return true; | |
} | |
} | |
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 TreeNode sortedArrayToBST(int[] num) { | |
return buildTree(num, 0, num.length); | |
} | |
public TreeNode buildTree(int[] num, int l, int h){ | |
int mid = ((h - l) / 2) + l; | |
TreeNode root = null; | |
if(h > l && mid >= 0 && mid < num.length){ |
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 List<List<Integer>> levelOrder(TreeNode root) { | |
// Tree maps keep a strict ordering of the values wtr to the order in which | |
// there inserted, necessary for keeping the level lists in order | |
Map<Integer, List<Integer>> treeList = new TreeMap<Integer, List<Integer>>(); | |
int level = 0; | |
if(root != null){ | |
List<Integer> rootLevelList = new ArrayList<Integer>(1); | |
rootLevelList.add(root.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
#include <stdio.h> | |
/* Stack ops */ | |
void push(void *); | |
void *pop(); | |
int isEmpty(); | |
void * peak(); | |
void processNode(TreeNode *); |
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
#include <stdio.h> | |
/* Stack ops */ | |
void push(void *); | |
void *pop(); | |
int isEmpty(); | |
void * peak(); | |
void processNode(TreeNode *); |
OlderNewer