Triplet
·
Algorithm/Codility
package codility.num6; import java.util.Arrays; public class Triplet { public int solution(int[] A) { // write your code in Java SE 8 Arrays.sort(A); // 1. 셋 다 양수 또는 음수일 경우, 뒤에서부터 3개 곱해주는게 best case int answer = A[A.length -1] * A[A.length -2] * A[A.length -3]; // 2. 맨 앞 두 수가 음수이고, 나머지 하나가 양수일 경우 // 맨 앞 두 수 * 맨 뒤 숫자 int answer2 = A[0] * A[1] * A[A.length -1]; // 두 값 중 큰 값 리턴 return Math.max(answ..
Codility - Distinct
·
Algorithm/Codility
https://app.codility.com/programmers/lessons/6-sorting/distinct/start/ Codility Your browser is not supported You should use a supported browser. Read more app.codility.com package codility.num6; import java.util.HashSet; public class Sorting { public int solution(int[] A) { // write your code in Java SE 8 // 중복된 값을 허용하지 않는 HashSet 사용 HashSet hs = new HashSet(); for(int a : A){ hs.add(a); } // S..
Stack - Fish
·
Algorithm/Codility
package codility.num5; import java.util.Stack; public class Solution { public int solution(int[] A, int[] B) { // write your code in Java SE 8 Stack aliveFish = new Stack(); // 시작 인덱스 추가 aliveFish.push(0); int i = 1; while (i A[aliveFish.peek()]){ // 살아남은 물고기 스택에서 현재 물고기를 pop aliveFi..
Lesson7 - Brackets
·
Algorithm/Codility
https://app.codility.com/programmers/lessons/7-stacks_and_queues/brackets/ Brackets coding task - Learn to Code - Codility Determine whether a given string of parentheses (multiple types) is properly nested. app.codility.com A 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}" wher..
Lesson2. OddCurrencesInArray
·
Algorithm/Codility
A non-empty array A consisting of N integers is given. The array contains an odd number of elements, and each element of the array can be paired with another element that has the same value, except for one element that is left unpaired. For example, in array A such that: A[0] = 9 A[1] = 3 A[2] = 9 A[3] = 3 A[4] = 9 A[5] = 7 A[6] = 9 the elements at indexes 0 and 2 have value 9, the elements at i..
Lesson2. CyclicRotation
·
Algorithm/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, 7] (elements are shifted right by one index and 6 is moved to the first place). The goal is to rotate array A K times; that is, each element ..
Lesson1. Binary Gap
·
Algorithm/Codility
https://app.codility.com/programmers/lessons/1-iterations/ 문제 : 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 number 529 has binary representation 1000010001 and contains two binary gaps:..
takoyummy
'Algorithm/Codility' 카테고리의 글 목록