Skip to content

Instantly share code, notes, and snippets.

View clarkdo's full-sized avatar

Xin Du (Clark) clarkdo

  • Dublin, Ireland
View GitHub Profile
<template>
<section>
<Btn/>
</section>
</template>
<script>
export default {
components: {
Btn: Button
class Solution {
public int solution(int N) {
int A = (int)Math.round(Math.sqrt(N));
while (N % A != 0) A--;
return 2*(A + N/A);
}
}
class Solution {
public int solution(int[] A) {
int len = A.length;
if (len == 0) return 0;
int min = A[0];
int profits = 0;
for (int i = 1; i < len; i++) {
int price = A[i];
if (price < min) {
min = price;
class Solution {
public int solution(int[] A) {
int length = A.length;
int leader = A[0];
int votes = 1;
//Boyer–Moore majority vote algorithm
for (int i = 1; i < length; i++) {
int digit = A[i];
import java.util.List;
import java.util.ArrayList;
class Solution {
public int solution(String S) {
if (S == null || S.length() == 0) return 1;
if (S.length() % 2 != 0) return 0;
char first = S.charAt(0);
if (first != '{' && first != '[' && first != '(') return 0;
import java.util.*;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
Arrays.sort(A);
int length = A.length;
import java.util.Set;
import java.util.HashSet;
// you can write to stdout for debugging purposes, e.g.
// System.out.println("this is a debug message");
class Solution {
public int solution(int[] A) {
Set<Integer> distincts = new HashSet<>();
for (int i: A) {
import java.util.Arrays;
class Solution {
public int solution(int[] A) {
if (A == null || A.length < 3) return 0;
int max = Integer.MAX_VALUE;
Arrays.sort(A);
long last = A[A.length-1];
for (int i = 0; i < A.length-2; i++) {
long P = A[i];
class Solution {
public int solution(int[] A) {
int pairs = 0;
int easts = 0;
for (int i : A) {
if (i == 0) {
easts++;
} else {
pairs += easts;
}
class Solution {
public int solution(int A, int B, int K) {
return B/K - (A == 0 ? -1 : (A-1)/K);
}
}