Skip to content

Instantly share code, notes, and snippets.

View wushbin's full-sized avatar

Shengbin Wu wushbin

  • San Francisco Bay Area
View GitHub Profile
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;
import javafx.util.Pair;
import org.junit.Assert;
import org.junit.Test;
import java.io.*;
import java.util.*;
public class WordPack {
class InputValues {
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 {
import org.junit.Test;
import java.io.*;
import java.util.*;
public class HilbertCurve {
class InputValues {
int x;
int y;
int n;
import org.junit.Test;
import java.io.*;
import java.util.*;
public class FindLakes {
class InputValues {
int n;
int[] terrain;
int w;
import org.junit.Assert;
import org.junit.Test;
import java.io.*;
import java.util.*;
public class CSV {
class InputValues {
String cmd;
int n;
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) {
/*
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]);
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]);
}
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) {