본문 바로가기

Computer Engineering16

Codility - Nesting Task descriptionA 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 string "())" isn't.Write a function:class Solution { public int solution(String S); }that, given a string S consisting of N chara.. 2014. 10. 25.
Codility - Brackets https://codility.com/demo/results/demoU2WQCE-QXU/ Task descriptionA string S consisting of N characters is considered to be properly nested if any of the following conditions is true:S is empty;S has the form "(U)" or "[U]" or "{U}" where U is a properly nested string;S has the form "VW" where V and W are properly nested strings.For example, the string "{[()()]}" is properly nested but "([)()]" .. 2014. 10. 25.
Codility NumberOfDiscIntersections https://codility.com/demo/results/demo5472KB-8BH/ -------------------------문제---------------------------Given an array A of N integers, we draw N discs in a 2D plane such that the I-th disc is centered on (0,I) and has a radius of A[I]. We say that the J-th disc and K-th disc intersect if J ≠ K and J-th and K-th discs have at least one common point.Write a function:class Solution { public int so.. 2014. 10. 25.
Codility - Triangle https://codility.com/demo/results/demoMMUZP3-QE3/ 주어진 문제를 제대로 읽자.. 난또 triangle이 이루어질 수 있는 조합의 개수인줄 알고 삽질하고 있었다. 근데 문제는 triangle이 있으면 1, 없으면 0을 출력하라는 문제였다. -------------------------- 만약 triangle이 이루어지는 조합의 개수를 출력하라고 했으면 어땠을까? 머리속에 드는 생각은 O(N*NlogN)이 아닌 O(N^2) 의 방법 밖에 생각이 안든다... 2014. 10. 25.
Codility - MaxProductOfThree https://codility.com/demo/results/demo35YHWV-DS4/ 중복값이 허용되는 배열에 귀신이라도 씌였나부다. 배열 정렬 이후 최대값 (오름차순으로 정렬했다 치고) 배열 뒤에서 3개만 곱하면 되겟지라고 생각했는데 어?! 중복값이 있으면 어떡하지, 라는 생각이 문뜩들었다. 괜한 생각이었다.. 중복값이 있어서 뒤에서 3개가 가장 큰값인데.. 거기다 문제에서 주어진 값의 범위가 -1000 ~ 1000 까지다. 맨 처음, 두번째가 마이너스라면 곱하기 하면 플러스.. 즉, 가장 작은값 2개가 마이너스면, 이 둘을 곱하면 가장 큰값이 된다. 그리고 가장 큰값인 제일 뒤에값과 곱하면 제일 커질수 있는 가정이 생긴다. 그렇기 때문에 가장 작은 2개의 값과 마지막값 ,,,,,,,, 맨 마지막 .. 2014. 10. 25.
Codility Distict https://codility.com/demo/results/demoTJHB47-7XW/ 중복값을 허용하는 숫자 배열에서 각각의 distict한 숫자의 개수가 몇개 인지 출력하는 문제.. 문제를 제대로 이해 못해서, 존재하지 않는 숫자를 출력하라는 줄 알았다.. NlogN의 시간복잡도를 가지니 해쉬를 이용해서 풀면 간단하다. 2014. 10. 25.