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
package com.algoritms; | |
import org.junit.Test; | |
import java.util.ArrayDeque; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.Collections; | |
import java.util.Deque; | |
import java.util.HashMap; |
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
class Solution { | |
public int findKthLargest(int[] nums, int k) { | |
PriorityQueue<Integer> maxHeap = new PriorityQueue<>(); | |
for(int num : nums){ | |
maxHeap.add(num); | |
if(maxHeap.size()>k){ | |
maxHeap.poll(); | |
} | |
} | |
return maxHeap.poll(); |
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
class Solution { | |
public int[][] kClosest(int[][] points, int k) { | |
int [][] res = new int[k][2]; | |
PriorityQueue<int[]> maxHeap = new PriorityQueue<>(points.length, | |
new Comparator<int[]>(){ | |
@Override | |
public int compare(int[] o1, int[]o2){ | |
double d1 = distance(o1); | |
double d2 = distance(o2); | |
if(d1==d2) return 0; |
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
package com.task.data.remote | |
import com.task.data.Resource | |
import com.task.data.dto.recipes.Recipes | |
import com.task.data.dto.recipes.RecipesItem | |
import com.task.data.error.NETWORK_ERROR | |
import com.task.data.error.NO_INTERNET_CONNECTION | |
import com.task.data.remote.service.RecipesService | |
import com.task.utils.NetworkConnectivity | |
import retrofit2.Response |
OlderNewer