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 solution(int[] A) { | |
int min = A.length + 1; | |
int length = A.length; | |
boolean[] appearance = new boolean[length]; | |
for (int i = 0; i < length; i++) { | |
if (A[i] > 0 && A[i] <= length) { | |
appearance[A[i]-1] = true; | |
} | |
} |
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 solution(int X, int[] A) { | |
int second = -1; | |
int count = 0; | |
boolean[] counter = new boolean[X]; | |
for (int i = 0; i < A.length; i++) { | |
int pos = A[i]; | |
if (pos <= A.length && !counter[pos-1]) { | |
counter[pos-1] = true; | |
count++; |
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 solution(int[] A) { | |
int length = A.length; | |
boolean[] appearance = new boolean[length]; | |
int count = 0; | |
for (int i : A) { | |
int position = i-1; | |
if (i <= length && !appearance[position]) { | |
appearance[position] = true; | |
count++; |
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
// 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<>(); |
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[] 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]; |
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 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); |
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 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); |
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 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; |
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 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")); |