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 ZipInt { | |
| public static void main(String[] argv) { | |
| ZipInt zi = new ZipInt(); | |
| System.out.println(zi.solution(12, 56)); | |
| System.out.println(zi.solution(56, 12)); | |
| System.out.println(zi.solution(12345, 678)); | |
| System.out.println(zi.solution(123, 67890)); | |
| System.out.println(zi.solution(10, 100)); | |
| System.out.println(zi.solution(0, 0)); | |
| System.out.println(zi.solution(2, 0)); |
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
| """ | |
| a graph API script to press like on all statuses posted by target user | |
| """ | |
| import requests # Use 3rd party request module for http request. | |
| import json | |
| import time | |
| """ | |
| search for your target user name in desktop version facebook. | |
| when you press enter, you could see URL like https://www.facebook.com/profile.php?id=##############&fref=ts for a while |
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 Point { | |
| double x; | |
| double y; | |
| String type; | |
| public Point() { | |
| } | |
| public Point(Point other) { | |
| this(other.type, other.x, other.y); |
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 int uniqueLength(String str) { | |
| char[] s = str.toCharArray(); | |
| Set<Character> showed = new HashSet<Character>(); | |
| int front = 0; | |
| int back = 0; | |
| int maxLen = 0; | |
| // unique substring [back: front - 1] | |
| while (front < s.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
| sort(Integer[] A, Comparator <Integer>() { | |
| @Override | |
| public int compare(Integer a, Integer b) { | |
| final boolean aEven = (a % 2) == 0; | |
| final boolean bEven = (b % 2) == 0; | |
| if ((aEven && bEven )|| (!aEven && !bEven)) { | |
| return a - b; | |
| } else { | |
| return (aEven)? -1: 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
| public void evenOdd(int[] A) { | |
| // [0: even - 1] // even | |
| // [even: odd] // unsorted | |
| // [odd + 1: A.length - 1] // odd | |
| int even = 0; | |
| int odd = A.length - 1; | |
| while (even <= odd) { | |
| if (A[even] % 2 == 0) { | |
| even++; | |
| } else { |
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
| // wrong | |
| public int ways(int x) { | |
| int[] ans = new int[x + 1]; | |
| for (int i = 1; i < ans.length; i++) { | |
| if (i == 1 || i == 5 || i == 10) { | |
| ans[i] += 1; | |
| } | |
| if (i - 1 > 0) { | |
| ans[i] += ans[i - 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
| // without parent | |
| public Node findCommonAncestor(Node root, Node n1, Node n2) { | |
| if (root == null) { | |
| return null; | |
| } else if (root == n1 || root == n2) { | |
| return root; | |
| } else { | |
| Node leftAnc = findCommonAncestor(root.left, n1, n2); | |
| Node rightAnc = findCommonAncestor(root.right, n1, n2); |
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 uniqueChar(String str) { | |
| Set<Character> showed = new HashSet<Character>(); | |
| StringBuilder sb = new StringBuilder(); | |
| for (int i = 0; i < str.length(); ++i) { | |
| final char c = str.charAt(i); | |
| if (!showed.contains(c)) { | |
| showed.add(c); | |
| sb.append(c); | |
| } |
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.Map; | |
| public class GuessNumber { | |
| public static void main(String[] argv) { | |
| GuessNumber gn = new GuessNumber(); | |
| gn.entry(); | |
| } |