Skip to content

Instantly share code, notes, and snippets.

@leearmee35
leearmee35 / 264. Ugly Number II.java
Created March 5, 2017 04:18
264. Ugly Number II
public class Solution {
public int nthUglyNumber(int n) {
PriorityQueue<Long> list = new PriorityQueue<Long>();
HashMap<Long, Integer> map = new HashMap<Long, Integer>();
long kkk = 1;
list.add(kkk);
long[] nums = new long[3];
nums[0] = 2;
nums[1] = 3;
nums[2] = 5;
@leearmee35
leearmee35 / 373. Find K Pairs with Smallest Sums.java
Created March 5, 2017 01:47
373. Find K Pairs with Smallest Sums
public class Solution {
public List<int[]> kSmallestPairs(int[] nums1, int[] nums2, int k) {
PriorityQueue<Tuple> pq = new PriorityQueue<Tuple>();
int m = nums1.length, n = nums2.length;
List<int[]> res = new ArrayList<int[]>();
if(nums1 == null || nums1.length == 0 || nums2 == null || nums2.length == 0 || k <= 0) return res;
for(int j = 0; j <= n-1; j++) {
pq.offer(new Tuple(0, j, nums1[0]+nums2[j]));
@leearmee35
leearmee35 / 133. Clone Graph.java
Created March 4, 2017 05:06
133. Clone Graph
/**
* Definition for undirected graph.
* class UndirectedGraphNode {
* int label;
* List<UndirectedGraphNode> neighbors;
* UndirectedGraphNode(int x) { label = x; neighbors = new ArrayList<UndirectedGraphNode>(); }
* };
*/
public class Solution {
public UndirectedGraphNode cloneGraph(UndirectedGraphNode node) {
public class Solution {
public int[] twoSum(int[] nums, int target) {
int[] res = new int[2];
HashMap<Integer, Integer> map = new HashMap<Integer, Integer>();
for(int i=0;i<nums.length;i++){
System.out.println(i);
if(map.get(target-nums[i])!=null){
res[0] = map.get(target-nums[i]);
@leearmee35
leearmee35 / 222. Count Complete Tree Nodes.java
Created March 3, 2017 00:04
222. Count Complete Tree Nodes
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
@leearmee35
leearmee35 / 209. Minimum Size Subarray Sum.java
Created March 2, 2017 23:16
209. Minimum Size Subarray Sum
public class Solution {
public int minSubArrayLen(int s, int[] nums) {
if (a == null || a.length == 0)
return 0;
int i = 0, j = 0, sum = 0, min = Integer.MAX_VALUE;
while (j < a.length) {
sum += a[j++];
@leearmee35
leearmee35 / 436. Find Right Interval.java
Created March 2, 2017 22:58
436. Find Right Interval
/**
* Definition for an interval.
* public class Interval {
* int start;
* int end;
* Interval() { start = 0; end = 0; }
* Interval(int s, int e) { start = s; end = e; }
* }
*/
public class Solution {
@leearmee35
leearmee35 / 287. Find the Duplicate Number.java
Created March 2, 2017 22:34
287. Find the Duplicate Number
public class Solution {
public int findDuplicate(int[] nums) {
int low = 1, high = nums.length - 1;
while (low <= high) {
int mid = (int) (low + (high - low) * 0.5);
int cnt = 0;
for (int a : nums) {
if (a <= mid) ++cnt;
@leearmee35
leearmee35 / 287. Find the Duplicate Number.java
Created March 2, 2017 22:34
287. Find the Duplicate Number
public class Solution {
public int findDuplicate(int[] nums) {
int low = 1, high = nums.length - 1;
while (low <= high) {
int mid = (int) (low + (high - low) * 0.5);
int cnt = 0;
for (int a : nums) {
if (a <= mid) ++cnt;
public class Solution {
public int hIndex(int[] citations) {
int low = 0, high = citations.length-1;
int res = 0;
while(low<=high){
int mid = low+(high-low)/2;
System.out.println(mid);
int h = citations.length-mid;