알고리즘 풀이/Codility

12345678910111213141516171819202122232425262728293031323334353637 public int solution(int[] A) { // write your code in Java SE 8 if(A.length==0) return -1; HashMap hm = new HashMap(); int max=1; for(int a : A){ if(!hm.containsKey(a)) hm.put(a,1); else { hm.put(a, hm.get(a)+1); if(max
1234567891011121314151617181920 public int solution(int[] H) { // write your code in Java SE 8 Stack st = new Stack(); int answer = 0; for(int h : H){ while(!st.isEmpty() && st.peek()>h){ st.pop(); } if(st.isEmpty() || st.peek()
1234567891011121314151617181920 public int solution(String S) { // write your code in Java SE 8 Stack st = new Stack(); for(int i=0; i
1234567891011121314151617181920212223242526272829 public int solution(int[] A, int[] B) { // write your code in Java SE 8 Stack st = new Stack(); for(int i=A.length-1; i>=0 ; i--){ if(st.isEmpty()) st.push(i); else { while(true){ if( B[st.peek()] == 0 && B[i] ==1 ){ if(A[i]>A[st.peek()]) st.pop(); else break; } else { st.push(i); break; } if(st.isEmpty()) { st.push(i); break; } } } } return st.s..
12345678910111213141516171819202122232425262728293031323334353637 public int solution(String S) { // write your code in Java SE 8 System.out.println(S); Stack st = new Stack(); for(int i=0; i
N개수 10만개 보고 sorting 하는 것을 두려워하지 말자.. 할거 다 해보고 도저히 모르겠을 때 해답보기, 오버플로우를 대비해서 이항시켜주기 1234567891011121314 public int solution(int[] A) { // write your code in Java SE 8 if(A.length=2; i--){ if(A[i-1]>A[i-2]-A[i] && A[i-2]>A[i]-A[i-1] && A[i]>A[i-1]-A[i-2]) return 1; } return 0; }Colored by Color Scriptercs ※ 알고보니 저 트라이앵글 식 중에 마지막 식만 만족해도 앞에 2개식도 만족하는 구도인 것을 알게됨
12345678 public int solution(int[] A) { // write your code in Java SE 8 HashSet hs = new HashSet(); for(int a : A) hs.add(a); return hs.size(); }Colored by Color Scriptercs
+++큰 순으로 3개 --작은순으로 2개 & +큰순으로 1개 1234567891011121314151617 public int solution(int[] A) { // write your code in Java SE 8 Arrays.sort(A); int leng = A.length; // for(int a : A ) System.out.println(a); int mmp = A[0]*A[1]*A[leng-1]; int ppp = A[leng-1]*A[leng-2]*A[leng-3]; return (mmp>ppp)?mmp:ppp; }Colored by Color Scriptercs
1. K로 나눠지는 가장 첫번째 인자 x(A
수학적 지식이 필요한 문제, 사실상 전형적 코테용 알고리즘은 아니라고봄.. 물론 당연히 못풀었고 수학적 지식을 활용한 풀이기법만 익히면 1분컷 가능한 문제 (2,3개의 최소평균값의 첫번째 인덱스 구하기 문제) 12345678910111213141516171819202122 public int solution(int[] A) { // write your code in Java SE 8 double minValue = (double) Integer.MAX_VALUE; int min = 0; for (int i = 0; i
배게
'알고리즘 풀이/Codility' 카테고리의 글 목록