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
/*********** Checking for not defined / undefined **********/ | |
foo | |
// ReferenceError: foo is not defined | |
if(foo == null) console.log('this wont work'); | |
// ReferenceError: foo is not defined | |
if (typeof foo == 'undefined' ) console.log('foo is undef'); | |
// this is the only way to check for not defined |
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
function Node (data) { | |
this.left = void(0); | |
this.right = void(0); | |
this.data = data; | |
} | |
var root = new Node ('F'); | |
root.left = new Node('B'); | |
root.right = new Node('G'); |
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
# .bash_profile | |
# Get the aliases and functions | |
if [ -f ~/.bashrc ]; then | |
. ~/.bashrc | |
fi | |
#JDK related exports | |
export JAVA_HOME=/bin/jdk1.6.0_31/bin/java | |
export PATH=$PATH:$HOME/bin |
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
// used to print format print. %n is new line. dont use \n | |
// http://docs.oracle.com/javase/tutorial/java/data/numberformat.html | |
System.out.format("The value of sum is: %.2f%n", 4650/100); | |
//Rotates a matrix right | |
public static void rotateRight(char[][] matrix) { | |
int cols = matrix[0].length; | |
int rows = matrix.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
import java.util.Arrays; | |
import java.util.Scanner; | |
import static java.lang.System.out; | |
/** | |
* Idea: if any col or row is odd, then set row or column to be corrupted | |
* | |
* if more than 1 row or col is corrupted, then its deadEnd. | |
* else | |
* output the particular row or col to be flipped in order to fix it |
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.util.Arrays; | |
import java.util.Scanner; | |
import java.util.BitSet; | |
import static java.lang.System.out; | |
/** | |
* Exhaustive search is used here. | |
* Spent 30 mins thinking about how to optimize the nasty N^2 maxtrix traversal but to no avail. | |
* So i simply submitted a brute force method and surprisingly got an AC :) | |
* |
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.util.Arrays; | |
import java.util.Scanner; | |
import static java.lang.System.out; | |
/** | |
* mistake: never read question properly. we need to calculate i upto and including j. | |
* hence for(; i<= j; i++) not for(; i< j; i++) | |
* the latter is done out of habbit =/ | |
*/ | |
public class Main { |
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.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.Arrays; | |
import java.util.HashMap; | |
import java.util.Scanner; | |
import static java.lang.System.out; | |
/** | |
* mistake: did not use BufferedReader to read in large files, resulting in very slow run time :-( |
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.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.Arrays; | |
import java.util.HashMap; | |
import java.util.LinkedList; | |
import java.util.Scanner; | |
import static java.lang.System.out; | |
/** |
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.BufferedOutputStream; | |
import java.io.BufferedWriter; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.OutputStream; | |
import java.io.OutputStreamWriter; | |
import java.io.PrintWriter; | |
import java.io.Writer; | |
import java.util.Arrays; | |
import java.util.InputMismatchException; |
OlderNewer