Skip to content

Instantly share code, notes, and snippets.

@xynophon
xynophon / SameTree.java
Last active August 29, 2015 14:24
LeetCode SameTree
import java.util.*;
public class SameTree {
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
import java.util.Arrays;
import java.util.HashMap;
/**
* Created by xynophon on 15.2.27.
*/
public class majorityElement {
public int majorityElement(int[] num) {
//bad solution using Hash. O(n). it took 343ms.
int half = num.length/2;
import java.util.Scanner;
/**
* Created by xynophon on 15.1.27.
*/
public class roman_2_integer{
// I 1
// IV 4
import java.util.Scanner;
/**
* Created by xynophon on 15.1.27.
*/
public class Unique_Binary_Search_Trees {
public int solution(int n){
int dbnum = 2*n;
long result = 1;
int cnt = 0;
/**
* Created by xynophon on 15.1.17.
*/
import java.util.Scanner;
public class search {
public int binary_search_iter(int[] arr, int target){
int lo = 0;
int hi = arr.length;
@xynophon
xynophon / sort.java
Last active September 21, 2018 00:00
/**
* Created by xynophon on 15.1.17.
*/
import java.util.Random;
import java.util.Scanner;
public class sort {
public int[] swap(int[] arr, int i, int j){
int temp = arr[i];
arr[i] = arr[j];
@xynophon
xynophon / EditAACUnit.java
Last active July 10, 2017 05:42
VoiceRecorder edit recorded file
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.util.HashMap;
import android.util.Log;
import java.util.Scanner;
/**
* Created by xynophon on 15.1.14.
*/
public class Excelsheetcolumnnumber {
public int titleToNumber(String s) {
int num = s.charAt(0)-64;
for(int i = 1; i < s.length(); i++){
num = 26 * num + (s.charAt(i)-64);
import java.util.Scanner;
/**
* Created by xynophon on 15.1.13.
*/
public class FactorialTrailingZeroes {
public long trailingZeroes(int n) {
int count = 0;
if(n < 1) return 0;
/**
* Created by xynophon on 15.1.13.
*/
public class binary_search {
public int binary_search(double[] arr, double target){
int lo = 0;
int hi = arr.length;
while(lo+1 < hi){
int mid = (lo+hi)/2;