Skip to content

Instantly share code, notes, and snippets.

import java.math.BigInteger;
import java.util.HashMap;
public class Codec {
String header = "http://tinyurl.com/";
static BigInteger num = new BigInteger("0");
String t = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
HashMap<String, String> decoding = new HashMap<>();
HashMap<String, String> encoding = new HashMap<>();
public class MedianofTwoSortedArrays {
public double findMedianSortedArrays(int[] nums1, int[] nums2) {
int[] merged = new int[nums1.length + nums2.length];
int i = 0;
int j = 0;
int k = 0;
int target_index = (nums1.length + nums2.length)/2;
while(i <= target_index){
@xynophon
xynophon / ColossusExample.scala
Last active February 28, 2017 02:30
Colossus Example
import colossus._
import core._
import service._
import protocols.http._
import UrlParsing._
import HttpMethod._
import akka.actor.ActorSystem
import colossus.task.Task
import com.typesafe.scalalogging.slf4j.LazyLogging
@xynophon
xynophon / ColossusSample.scala
Last active February 13, 2017 10:27
tumblr Colossus
import colossus._
import core._
import service._
import protocols.http._
import UrlParsing._
import HttpMethod._
import akka.actor.ActorSystem
import org.json4s.jackson.Serialization
class SampleService(context: ServerContext) extends HttpService(context) {
import java.util.*;
public class CountingBits {
public int[] countBits(int num) {
int[] result = new int[num+1];
int base = 0;
for(int i = 0; i <= num; i++){
double logvalue = Math.log(i)/Math.log(2);
if(logvalue == (int)logvalue){
base = i;
@xynophon
xynophon / HappyNumber.java
Created August 20, 2015 15:51
LeetCode Happy Number
import java.util.*;
public class HappyNumber {
public boolean isHappy(int n) {
HashSet<Integer> sum_set = new HashSet<>();
int sum = 0;
while(n != 1) {
while (n > 0) {
sum += Math.pow(n % 10, 2);
n /= 10;
@xynophon
xynophon / PopulatingNextRightPointersinEachNodeII.java
Created August 20, 2015 09:14
LeetCode Populating Next Right Pointers in Each Node II
import java.util.*;
public class PopulatingNextRightPointersinEachNodeII {
public class TreeLinkNode {
int val;
TreeLinkNode left, right, next;
TreeLinkNode(int x) { val = x; }
}
public void connect(TreeLinkNode root) {
@xynophon
xynophon / BinaryTreeLevelOrderTraversal.java
Created August 18, 2015 07:05
LeetCode Binary Tree Level Order Traversal
import java.util.*;
public class BinaryTreeLevelOrderTraversal {
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
@xynophon
xynophon / MeetingRooms.java
Created August 16, 2015 13:04
LeetCode Meeting Rooms
import java.util.*;
public class MeetingRooms {
public class Interval {
int start;
int end;
Interval() {
start = 0;
@xynophon
xynophon / ReverseWordsinaStringII.java
Last active August 29, 2015 14:27
LeetCode Reverse Words in a String 2
import java.util.*;
public class ReverseWordsinaStringII {
public void reverseWords(char[] s) {
int start = 0;
int end = 0;
for (int i = 0; i < s.length; i++) {
if(s[i] == ' '){
end = i-1;
reverse(s, start, end);