8/11
·
TIL
Today's Codekataclass Solution { public String solution(String X, String Y) { int[] xCount = new int[10]; int[] yCount = new int[10]; for (char ch : X.toCharArray()) { xCount[ch - '0']++; } for (char ch : Y.toCharArray()) { yCount[ch - '0']++; } StringBuilder answer = new StringBuilder(); for (int i = 9; i >= 0; i--..
8/10
·
TIL
Today's Codekata// 로또의 최고 순위와 최저 순위class Solution { public int[] solution(int[] lottos, int[] win_nums) { int[] answer = new int[2]; int high = 0; int low = 0; for (int i = 0; i // 옹알이(2)class Solution { public int solution(String[] babbling) { int answer = 0; String[] sounds = {"aya", "ye", "woo", "ma"}; for (String word : babbling) { ..
8/9
·
TIL
Today's Codekata// 기사단원의 무기class Solution { public int solution(int number, int limit, int power) { int answer = 0; while (number > 0) { int damage = 0; for (int i = 1; i limit) { damage = power; } answer += damage; number--; } return answer; }}class Solution { public int s..
8/8
·
TIL
Today's Codekata// 소수 만들기class Solution { public int solution(int[] nums) { int answer = 0; for (int i = 0; i 코드도 길고 비효율적으로 보이기도 하지만 정답에 도달했음에 만족한다.// 덧칠하기class Solution { public int solution(int n, int m, int[] section) { int answer = 0; int painted = 0; for (int i = 0; i painted) { painted = section[i] + m - 1; ans..
8/7
·
TIL
Today's Codekata// 과일 장수class Solution { public int solution(int k, int m, int[] score) { int answer = 0; Arrays.sort(score); for (int i = score.length - m; i >= 0; i-=m) { int p = score[i]; answer += p * m; } return answer; }}for문에서 1씩 더하거나 1씩 빼거나만 생각했었는데, 조금만 생각해보면 더 다양하게 활용이 가능하다는 걸 깨달았다.// 모의고사class Solution { public int[] sol..
8/6
·
TIL
Today's Codakata// 카드 뭉치class Solution { public String solution(String[] cards1, String[] cards2, String[] goal) { String answer = "Yes"; int i = 0, j = 0, k = 0; while (i 뭔가 아쉬움이 남아서 향상된 for문으로 리팩토링해봤다.-- 특정 옵션이 포함된 자동차 리스트 구하기SELECT CAR_ID, CAR_TYPE, DAILY_FEE, OPTIONSFROM CAR_RENTAL_COMPANY_CARWHERE OPTIONS LIKE '%네비게이션%'ORDER BY CAR_ID DESC-- 조건에 부합하는 중고거래 상태 조회하기SELE..
8/5
·
TIL
Today's Codekata// 2016년class Solution { public String solution(int a, int b) { int[] month = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; String[] dayName = {"FRI","SAT","SUN","MON","TUE","WED","THU"}; int days = 0; for (int i = 0; i 처음엔 LocalDate에 있는 기능을 사용해서 답을 찾았는데, 알고리즘은 편리한 방법보다 어떻게하면 그 값을 구할 수 있는지에 대해 좀 더 근본적인 방법을 생각해보는 시간이라고 느껴서 배열을 활용해서 답을 찾아봤다.-- 과일로..
8/4
·
TIL
Today's Codekata// 콜라 문제class Solution { public int solution(int a, int b, int n) { int answer = 0; while (n >= a) { int newCola = (n / a) * b; answer += newCola; n = (n % a) + newCola; } return answer; }}// 명예의 전당class Solution { public int[] solution(int k, int[] score) { int[] answer = new int[score.length]; L..
8/3
·
TIL
Today's Codekata// 가장 가까운 같은 글자class Solution { public int[] solution(String s) { int[] answer = new int[s.length()]; for (int i = 0; i = 0; j--) { if (s.charAt(i) == s.charAt(j)) { answer[i] = i - j; break; } } } return answer; }}처음엔 `boolean`을 활용해서 `if`문 조건에 부합할 땐 true로 변경해주고 false일..
8/2
·
TIL
Today's Codekata// K번째 수class Solution { public int[] solution(int[] array, int[][] commands) { int[] answer = new int[commands.length]; for (int i = 0; i 몇 번째 몇 번째 라는 말은 인덱스 넘버에선 항상 -1 해서 생각해야한다는 걸 다시금 느끼게 해준 문제였다. 배열과 변수 idx를 활용하려는 생각은 좋았으나 그것들을 반복문을 돌면서 적절한 위치에서 초기화해줘야했으나 마지막에야 알게 되었다.// 두 개 뽑아서 더하기class Solution { public int[] solution(int[] numbers) { List results..