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.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<>(); |
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 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){ |
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 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 |
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 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) { |
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.*; | |
| 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; |
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.*; | |
| 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; |
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.*; | |
| public class PopulatingNextRightPointersinEachNodeII { | |
| public class TreeLinkNode { | |
| int val; | |
| TreeLinkNode left, right, next; | |
| TreeLinkNode(int x) { val = x; } | |
| } | |
| public void connect(TreeLinkNode root) { |
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.*; | |
| public class BinaryTreeLevelOrderTraversal { | |
| /** | |
| * Definition for a binary tree node. | |
| * public class TreeNode { | |
| * int val; | |
| * TreeNode left; | |
| * TreeNode right; | |
| * TreeNode(int x) { val = x; } |
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.*; | |
| public class MeetingRooms { | |
| public class Interval { | |
| int start; | |
| int end; | |
| Interval() { | |
| start = 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
| 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); |
NewerOlder