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 String returnOneLine(String filename) throws IOException { | |
| BufferedReader br = new BufferedReader(new FileReader(filename)); | |
| String result = br.readLine(); | |
| String tmp = null; | |
| int size = 2; | |
| while ((tmp = br.readLine()) != null) { | |
| int i = (int)(Math.random() * size++); | |
| if (i < 1) { | |
| result = tmp; |
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
| class Server { | |
| Map<Stock, StockTx> map = new HashMap<Stock, StockTx>(); | |
| public void publish() { | |
| Map<Stock, StockTx> mapBack = null; | |
| synchronized(this) { | |
| mapBack = map; | |
| map = new HashMap<Stock, StockTx>(); | |
| } | |
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 Solution { | |
| public ArrayList<ArrayList<Integer>> permute(int[] num) { | |
| ArrayList<ArrayList<Integer>> ans = new ArrayList<ArrayList<Integer>>(); | |
| final int N = num.length; | |
| if (N > 0) { | |
| perm(num, N, 0, ans); | |
| } | |
| return ans; | |
| } | |
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 SingletonMain { | |
| public static void main(String []argv) { | |
| EnumSingleton es = EnumSingleton.INSTANCE; | |
| ClassSingleton cs = ClassSingleton.getInstance(); | |
| } | |
| } | |
| enum EnumSingleton { | |
| INSTANCE; |
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.Scanner; | |
| public class HoneyComb { | |
| public static void main(String []argv) throws Exception { | |
| HoneyComb hc = new HoneyComb(); | |
| hc.enter(); | |
| } | |
| public void enter() { |
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 void method1(String filename) { | |
| BufferedReader br = new BufferedReader(new FileReader(filename)); | |
| int lineNum = 0; | |
| while (br.readLine() != null) { | |
| lineNum++; | |
| } | |
| br.close(); | |
| br = new BufferedReader(new FileReader(filename)); | |
| int line = (int)(Math.random() * lineNum); |
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 Solution { | |
| public static void main(String []argv) { | |
| BufferedReader br = new BufferedReader(new FileReader("....")); | |
| boolean prevHasError = false; | |
| int lineNum = 0; | |
| while (br.hasNext()) { | |
| String line = br.readLine(); | |
| boolean hasError = (line.indexOf("error") != -1); | |
| if (hasError || prevHasError) { |
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 Node removeNode(Node head, int val) { | |
| Node fakeHead = new Node(0); | |
| Node tail = fakeHead; | |
| while (head != null) { | |
| if (head.val != val) { | |
| tail.next = head; | |
| tail = tail.next; | |
| } | |
| head = head.next; |
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; | |
| import java.util.Comparator; | |
| import java.util.HashMap; | |
| public class TreeHierarchyPrint { | |
| public static void main(String[] argv) { | |
| TreeHierarchyPrint orderBy = new TreeHierarchyPrint(); | |
| orderBy.print( | |
| new String[][] { |
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.HashMap; | |
| import java.util.HashSet; | |
| import java.util.Map; | |
| public class MinimumWindowSubstring { | |
| public static void main(String []argv) { | |
| MinimumWindowSubstring mws = new MinimumWindowSubstring(); | |
| System.out.println(mws.minWindow("ADOBECODEBANC", "ABC")); | |
| System.out.println(mws.minWindow("aa", "aa")); |