This file contains 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 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; |
This file contains 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 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])); |
This file contains 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
/** | |
* 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) { |
This file contains 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 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]); |
This file contains 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
/** | |
* Definition for a binary tree node. | |
* public class TreeNode { | |
* int val; | |
* TreeNode left; | |
* TreeNode right; | |
* TreeNode(int x) { val = x; } | |
* } | |
*/ | |
public class Solution { |
This file contains 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 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++]; | |
This file contains 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
/** | |
* 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 { |
This file contains 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 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; |
This file contains 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 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; |
This file contains 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 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; |
NewerOlder