본문 바로가기

Counting Elements4

[codility] MaxCounters MaxCounters MaxCountersCalculate the values of counters after applying all alternating operations: increase counter by 1; set value of all counters to current maximum.Task Score100%Correctness100%Performance100% correctness 100%에 performance 0% 결과.. 시간복잡도 제한이 O(N+M) 인데 O(N*M) 이 나와버려서 40대의 점수가 나와버렸다. ㅠㅠ루프 하나에서 모든 값처리를 다 하려고 했던게 요인인 것 같다. x// you can also use imports, for example:import java.util... 2018. 5. 23.
[codility] PermCheck PermCheck PermCheckCheck whether array A is a permutation.Task Score100%Correctness100%Performance100% 순열인지 체크하는 문제이다. 1부터 N까지의 숫자가 다 들어있느냐 확인만 하면 되기 때문에 아주 간단하게 체킹할 수 있다. x// 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.. 2018. 5. 23.
[codility] MissingInteger MissingInteger MissingIntegerFind the smallest positive integer that does not occur in a given sequence.Task Score100%Correctness100%Performance100% 이것도 날아가서 의도치 않게 재도전 ^^..!HashMap은 key값이 같으면 2번 저장해도 1개만 입력되기 때문에 중복처리를 해줄 필요 없이 그냥 쭉쭉 전체를 입력해주면 된다. 그리고 1부터 A배열의 크기(N)까지 돌려주면서 빈 값을 찾는다. 만약 1부터 N까지의 값이 다 차있을 경우 반복문을 빠져나오고 N+1이 반환된다. x// you can also use imports, for example:import java.util.*;​// y.. 2018. 5. 23.
[codility] FrogRiverOne FrogRiverOne FrogRiverOneFind the earliest time when a frog can jump to the other side of a river.Task Score100%Correctness100%Performance100% 아 원래 풀어 두었던 코드가 날아가서 재시도 ㅠㅠ.... 원래 풀이가 뭐였는지 전혀 기억이 나지 않아 새로운 마음으로 HashMap클래스를 사용해서 풀었다.X보다 작은 값만 중복되지않게 맵에 넣어주면 1, 2, 3, ..., X가 되는 순간 hashmap의 size도 X와 같게 되기 때문에 그 순간의 key값을 return하도록 했다. xxxxxxxxxx// you can also use imports, for example:import java.uti.. 2018. 5. 23.