Level : WORDPRESS BOOK LINKEDIN PATENT Send Mail 동냥하기 hajunho.com

187

살며 생각하며, / / 2020. 4. 20. 23:03
반응형

https://brunch.co.kr/magazine/highschool

 

나는 고졸사원이다 매거진

#직장인 #회사원 #고졸사원

brunch.co.kr

솔직한 브런치라 좋다.

class Solution {

    public int solution(int[] A) {

        // write your code in Java SE 8

        int sum=0;       

        Arrays.sort(A);       

       

        for(int i=0; i < A.length ; i++) {

            if(A[i+1] - A[i] != 1) return A[i]+1;

        }

        return 0;

    }

}

 

class Solution { public int solution(int[] A) { // write your code in Java SE 8 int sum=0; for(int i=0; i < A.length ; i++) sum ^= A[i] ^ (i+1); return sum ^(A.length+1); } }

 

 

Task description

A zero-indexed array A consisting of N different integers is given. The array contains integers in the range [1..(N + 1)], which means that exactly one element is missing.

 

Your goal is to find that missing element.

 

Write a function:

 

class Solution { public int solution(int[] A); }

that, given a zero-indexed array A, returns the value of the missing element.

 

For example, given array A such that:

 

  A[0] = 2

  A[1] = 3

  A[2] = 1

  A[3] = 5

the function should return 4, as it is the missing element.

 

Assume that:

 

N is an integer within the range [0..100,000];

the elements of A are all distinct;

each element of array A is an integer within the range [1..(N + 1)].

Complexity:

 

expected worst-case time complexity is O(N);

expected worst-case space complexity is O(1), beyond input storage (not counting the storage required for input arguments).

Elements of input arrays can be modified.

Copyright 2009–2016 by Codility Limited. All Rights Reserved. Unauthorized copying, publication or disclosure prohibited.

반응형

'살며 생각하며,' 카테고리의 다른 글

189  (1) 2020.04.20
188  (0) 2020.04.20
186  (0) 2020.04.20
185 - raspberry pi 64 bit + tensorflow installation  (0) 2020.04.20
184  (0) 2020.04.20
  • 네이버 블러그 공유하기
  • 네이버 밴드에 공유하기
  • 페이스북 공유하기
  • 카카오스토리 공유하기