Find the earliest time when a frog can jump to the other side of a river.
Respectable
Calculate the values of counters after applying all alternating operations: increase counter by 1; set value of all counters to current maximum.
Respectable
Find the smallest positive integer that does not occur in a given sequence.
Painless
// you can also use imports, for example:
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);
if(A[A.length-1] < 0) return 1;
int ans = 0;
int prev = 0;
for(int i = 0; i < A.length; i++) {
if(A[i] < 0) continue;
if(A[i]-prev > 1) {
ans = prev+1;
break;
}
prev = A[i];
}
if(ans == 0) {
ans = A[A.length-1]+1;
}
return ans;
}
}
import java.util.ArrayList;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
class Solution {
public int solution(int[] A) {
ArrayList<Integer> numbers = IntStream.of(A).boxed().filter(x->x>0).sorted().distinct().collect(Collectors.toCollection(ArrayList<Integer>::new));
if (numbers.size() == 0)
return 1;
for (int i = 0; i < numbers.size(); i++) {
if (numbers.get(i) != i+1)
return i+1;
}
return numbers.size()+1;
}
}
이건 시도는 좋았으나 타임아웃에러남
▶large_2shuffled sequence 1, 2, ..., 100000 (without minus)✘TIMEOUT ERRORrunning time: 1.272 sec., time limit: 1.024 sec.
1.1.272 sTIMEOUT ERROR, running time: 1.272 sec., time limit: 1.024 sec.2.1.240 sTIMEOUT ERROR, running time: 1.240 sec., time limit: 1.008 sec.
Check whether array A is a permutation.
내 블로그 - 관리자 홈 전환 |
Q
Q
|
---|---|
새 글 쓰기 |
W
W
|
글 수정 (권한 있는 경우) |
E
E
|
---|---|
댓글 영역으로 이동 |
C
C
|
이 페이지의 URL 복사 |
S
S
|
---|---|
맨 위로 이동 |
T
T
|
티스토리 홈 이동 |
H
H
|
단축키 안내 |
Shift + /
⇧ + /
|
* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.