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 org.junit.Assert; | |
import org.junit.Test; | |
import java.io.*; | |
import java.util.*; | |
import java.util.regex.Matcher; | |
public class LongestDistance { | |
class InputValues { | |
int n; |
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 javafx.util.Pair; | |
import org.junit.Assert; | |
import org.junit.Test; | |
import java.io.*; | |
import java.util.*; | |
public class WordPack { | |
class InputValues { |
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 org.junit.Test; | |
import java.io.*; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.Scanner; | |
public class SpanningSubstring { | |
class InputValues { |
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 org.junit.Test; | |
import java.io.*; | |
import java.util.*; | |
public class HilbertCurve { | |
class InputValues { | |
int x; | |
int y; | |
int n; |
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 org.junit.Test; | |
import java.io.*; | |
import java.util.*; | |
public class FindLakes { | |
class InputValues { | |
int n; | |
int[] terrain; | |
int w; |
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 org.junit.Assert; | |
import org.junit.Test; | |
import java.io.*; | |
import java.util.*; | |
public class CSV { | |
class InputValues { | |
String cmd; | |
int n; |
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 List<String> ipToCIDR(String ip, long n) { | |
List<String> result = new ArrayList<>(); | |
long ipNum = 0; | |
String[] tokens = ip.split("\\."); | |
for (int i = 0; i < 4; i++) { | |
ipNum = ipNum * 256 + (long) Integer.parseInt(tokens[i]); | |
} | |
if (n + ipNum > 4294967296L) { | |
return result; | |
} else if (n == 4294967296L) { |
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
/* | |
Binary search and Greedy | |
*/ | |
public int allocatebooksII(int n, int B, int[] A) { | |
int sum = 0; | |
int max = Integer.MIN_VALUE; | |
for (int i = 0; i < n; i++) { | |
sum += A[i]; | |
max = Math.max(max, A[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
class Solution { | |
// vector solution | |
public double minAreaFreeRect(int[][] points) { | |
Map<Integer, Set<Integer>> map = new HashMap<>(); | |
for (int[] p : points) { | |
if (!map.containsKey(p[0])){ | |
map.put(p[0], new HashSet<>()); | |
} | |
map.get(p[0]).add(p[1]); | |
} |
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
class Solution { | |
public int smallestRepunitDivByK(int K) { | |
if (K == 2 || K == 5) { | |
return -1; | |
} | |
int num = 0; | |
for (int i = 1; i <= K; i++) { | |
num = (num * 10 + 1) % K; | |
if (num == 0) { |
NewerOlder