Skip to content

Instantly share code, notes, and snippets.

View clarkdo's full-sized avatar

Xin Du (Clark) clarkdo

  • Dublin, Ireland
View GitHub Profile
import com.google.common.collect.Lists;
import java.util.ArrayList;
import java.util.List;
public class SearchInList {
public static final ArrayList<List<String>> LIST = Lists.newArrayList(
Lists.newArrayList("a", "b"),
Lists.newArrayList("c", "d"),
import java.util.LinkedList;
public class DepthSearch {
private static final String START = "B";
private static final String END = "E";
public static void main(String[] args) {
// this graph is directional
Graph graph = new Graph();
import java.util.ArrayList;
import java.util.List;
public class TravelCost {
private final static Integer[][] participants = {{500, 700}, {200, 600}, {400, 500}, {600, 200}, {500,300}};
private final static int cityAmount = participants[0].length;
private final static List<Integer> result = new ArrayList<>();
public static void main(String[] args) {
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class NoRepeating {
public static void main(String[] args) {
System.out.println(find(null));
System.out.println(find(""));
System.out.println(find("111111"));
class Solution {
public int solution(int N) {
int current = N;
int max = 0;
int currentGap = 0;
boolean start = false;
while (current / 2 != 0) {
if (current % 2 != 0) {
max = currentGap > max ? currentGap : max;
currentGap = 0;
class Solution {
public int solution(int[] A) {
int sum = 0;
int diff = Integer.MAX_VALUE;
for (int i : A) {
sum += i;
}
for (int i = A.length -1; i > 0; i--) {
sum -= 2 * A[i];
int abs = Math.abs(sum);
class Solution {
public int solution(int[] A) {
int sum = 0;
int sumA = 0;
for (int i = 0; i < A.length; i++) {
int digit = i + 1;
sum += digit;
sumA += A[i];
}
return A.length + 1 - (sumA - sum);
class Solution {
public int[] solution(int N, int[] A) {
int[] result = new int[N];
int currentMax = 0;
int max = 0;
for (int i: A) {
if (i == N + 1) {
max = currentMax;
} else {
int digit = result[i-1];
class Solution {
public int solution(int[] A) {
int result = 0;
double best = Double.MAX_VALUE;
for (int i = 0; i < A.length - 1; i++) {
int sum = 0;
int increase = 0;
for (int j = i; j < A.length; j++) {
sum += A[j];
int count = j - i;
@clarkdo
clarkdo / Solution.java
Last active January 26, 2018 09:35
GenomicRangeQuery
// you can also use imports, for example:
import java.util.Map;
import java.util.HashMap;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int[] solution(String S, int[] P, int[] Q) {
Map<String, Integer> mapping = new HashMap<>();