반응형

https://app.codility.com/demo/results/trainingWSHSQ7-TFQ/

 

Test results - Codility

A non-empty array A consisting of N integers is given. A permutation is a sequence containing each element from 1 to N once, and only once. For example, array A such that: A[0] = 4 A[1] = 1 A[2] = 3 A[3] = 2 is a permutation, but array A such that: A[0] =

app.codility.com

 

배열 내에서 값이 순열인지 확인 하는 문제이다.

 

내가 푼 방법은 요소들의 합을 가지고 판단하는 로직으로 알고리즘을 짰지만....

 

퍼포먼스 쪽 부분의 점수가 높지 않다.... 뭔가 효율을 낼 수 있는 코드를 짤 수 있도록 더 생각해야겠다.

 

다음에 이걸 100% 올릴 수 있도록

반응형
반응형

https://app.codility.com/demo/results/trainingT2AFR4-G8F/

 

Test results - Codility

A string S consisting of N characters is called properly nested if: S is empty; S has the form "(U)" where U is a properly nested string; S has the form "VW" where V and W are properly nested strings. For example, string "(()(())())" is properly nested but

app.codility.com

에러가 나는 부분의 경우의 수를 어떤 걸 해야되는지 모르겠다.

추후에 다시 봐보자 

로직은 이상이 없는 것 같다.

반응형
반응형
int arrASize = A.length;
        int maxResult =0;
        int tempResult;

        for (int i = 0; i < arrASize - 2; i++) {
            for (int j = i + 1; j < arrASize - 1; j++) {
                for (int l = j + 1; l < arrASize; l++) {
                    tempResult = A[i] * A[j] * A[l];
                    if(i==0 && j==1 && l==2) {
                        maxResult = tempResult;
                    }

                    else if(maxResult < tempResult) {
                        maxResult = tempResult;
                    }
                }
            }

        }

        System.out.println(maxResult);
        return maxResult;

    }

위의 코드로 할 시 결과 값은 올바른 값이 나오지만... 효율이 정말 꽝인 코드이다.... 한마디로 시간 복잡도가 n의 3제곱 이 된다.

 

100%인 다른 분의 코드를 보니.........

배열의 sort 메소드를 이용하여 정렬을 한 뒤 맨 앞 3개의 값과 맨 뒤의 3개의 값을 비교하였다. 

곱셈의 성질 상 3개의 곱셈이 숫자가 크다고 언제나 높은 값이 아닌 음수, 양수 또한 따져야 하기 때문이다.....

 

배열의 순서는 상관이 없다.... 그 안에 값을 가지고 로직을 구현 하면 되는 것이었다.

소팅을 이용하면 단 2번의 곱셈으로로 최대 값을 알수 있는데.... 그걸 for 문으로 돌고 있었으니.... 효율이 꽝일 수 밖에.....

반응형
반응형

https://app.codility.com/demo/results/trainingA3P3PU-PBR/

 

Test results - Codility

An array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9,

app.codility.com

의견

배열을 알고 있고, 적당한 알고리즘을 사용하여 풀 수 있었다.

 

반응형
반응형

https://app.codility.com/demo/results/trainingZ55NFR-TDD/

 

Test results - Codility

A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the binary representation of N. For example, number 9 has binary representation 1001 and contains a binary gap of length 2. The

app.codility.com

어찌 어찌 100%로 통과 하긴 했는데.....

이지난이도도 이렇게 시간 오래 걸려서 풀게 되다니....

 

정규식, 자바Utils 등 여러가지를 활용 할 수 있어야 된다.

반응형

+ Recent posts