๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๋ฐ˜์‘ํ˜•

IT Blog404

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - (Level2)์˜ˆ์ƒ ๋Œ€์ง„ํ‘œ https://programmers.co.kr/learn/courses/30/lessons/12985 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ์ฝ”๋“œ class Solution { public int solution(int n, int a, int b) { int answer = 0; while(a != b){ answer ++; a = (a+1)/2; b = (b+1)/2; } return answer; } } ํ’€์ด ๋ฐฑ์ค€ 1057๋ฒˆ ํ† ๋„ˆ๋จผํŠธ ๋ฌธ์ œ์™€ ๋™์ผํ•˜๋‹ค. ๋”ฐ๋ผ์„œ ํ’€์ด๋Š” ์•„๋ž˜ ์‚ฌ์ดํŠธ ์ฐธ๊ณ  ! ํ’€์ด 2020. 3. 16.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - (Level2)์ฃผ์‹๊ฐ€๊ฒฉ https://programmers.co.kr/learn/courses/30/lessons/42584 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ์ฝ”๋“œ class Solution { public int[] solution(int[] prices) { int[] answer = new int[prices.length]; answer[prices.length-1] = 0; // ๋งˆ์ง€๋ง‰ ๊ฐ€๊ฒฉ์€ ๋–จ์–ด์งˆ ์ˆ˜ ์—†์œผ๋ฏ€๋กœ 0 for(int i=0; i prices[j]) - ๊ทธ ์‹œ๊ฐ„์€ j - i ๊ฐ€ ๋œ๋‹ค. ์œ„์˜ ์˜ˆ์—์„œ๋„ [1, 2, 3, 2, 3] 2๋ฒˆ์งธ๊ฐ’ 3๊ณผ 3๋ฒˆ.. 2020. 3. 16.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - (Level2)๊ฐ€์žฅ ํฐ ์ •์‚ฌ๊ฐํ˜•์ฐพ๊ธฐ(DP) https://programmers.co.kr/learn/courses/30/lessons/12905 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ์ฝ”๋“œ class Solution { public int solution(int [][]board) { int answer = 0; int[][] newBoard = new int[board.length+1][board[0].length+1]; // ์ƒˆ๋กœ์šด ๋ฐฐ์—ด ์ƒ์„ฑ for(int i=0; i 2020. 3. 16.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - (Level2)ํ”ผ๋ณด๋‚˜์น˜ ์ˆ˜(์žฌ๊ท€ , ๋น„์žฌ๊ท€DP) https://programmers.co.kr/learn/courses/30/lessons/12945 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ์ฝ”๋“œ1(๋น„์žฌ๊ท€, DP) class Solution { public int solution(int n) { int[] arr = new int[100001]; arr[1] = 1; arr[2] = 1; for(int i=3; i 2020. 3. 16.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - (Level2)ํƒ‘ https://programmers.co.kr/learn/courses/30/lessons/42588 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ์ฝ”๋“œ class Solution { public static int[] solution(int[] heights) { int[] answer = new int[heights.length]; answer[0] = 0; for(int i=heights.length-1; i>0; i--) { for(int j=i-1; j>=0; j--) { if(heights[i] < heights[j]) { answer[i] =.. 2020. 3. 16.
[Codeforces] 1303A: Erasing Zeroes https://codeforces.com/problemset/problem/1303/A Problem - 1303A - Codeforces codeforces.com ์ฝ”๋“œ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); for(int tc=0; tc 0์„ ํ•œ๊ฐœ๋งŒ ์ง€์šฐ๋ฉด ๋จ i.e) ๋ชจ๋“  ๋ฌธ์ž์—ด์ด 1์˜ ์—ฐ์†์ด์–ด์•ผํ•จ. ์ฃผ์–ด์ง„ ๋ฌธ์ž์—ด์—์„œ 1์ด ์‹œ์ž‘ํ•˜๋Š” ์ธ๋ฑ์Šค์™€ ๋๋‚˜๋Š” ์ธ๋ฑ์Šค๋ฅผ ์ฐพ๋Š”๋‹ค. - indexOf , lastIndexOf ๊ทธ ํ›„ ์‹œ์ž‘ ์ธ๋ฑ์Šค์™€ ๋ ์ธ๋ฑ์Šค๊ฐ€ 1์ธ ๋ฌธ์ž์—ด ์‚ฌ์ด์—์„œ 0์˜ ๊ฐฏ์ˆ˜๋ฅผ.. 2020. 3. 16.
[๋ฐฑ์ค€] 11945๋ฒˆ: ๋œจ๊ฑฐ์šด ๋ถ•์–ด๋นต https://www.acmicpc.net/problem/11945 11945๋ฒˆ: ๋œจ๊ฑฐ์šด ๋ถ•์–ด๋นต ์ž…๋ ฅ์œผ๋กœ ์ฃผ์–ด์ง€๋Š” ๊ฐ ํ–‰์„ ๋ฐ˜์ „์‹œ์ผœ์„œ ์ถœ๋ ฅํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์ž…๋ ฅ์˜ 1ํ–‰ 1์—ด์€ ์ถœ๋ ฅ์˜ 1ํ–‰ M์—ด๋กœ, ์ž…๋ ฅ์˜ 1ํ–‰ 2์—ด์€ ์ถœ๋ ฅ์˜ 1ํ–‰ M-1์—ด๋กœ … ์ž…๋ ฅ์˜ 1ํ–‰ M์—ด์€ ์ถœ๋ ฅ์˜ 1ํ–‰ 1์—ด๋กœ … ์ž…๋ ฅ์˜ Nํ–‰ M์—ด์€ ์ถœ๋ ฅ์˜ Nํ–‰ 1์—ด๋กœ ์ถœ๋ ฅํ•˜์„ธ์š”. www.acmicpc.net ์ฝ”๋“œ import java.io.*; public class Main { public static void main (String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw =.. 2020. 3. 13.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - (Level2)๋‹ค๋ฆฌ๋ฅผ ์ง€๋‚˜๋Š” ํŠธ๋Ÿญ https://programmers.co.kr/learn/courses/30/lessons/42583 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ์ฝ”๋“œ import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Queue; class Truck{ int weight; int index; public Truck(int weight, int index) { this.weight = weight; this.index = index; } } cla.. 2020. 3. 13.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - (Level2)์ตœ์†Ÿ๊ฐ’ ๋งŒ๋“ค๊ธฐ https://programmers.co.kr/learn/courses/30/lessons/12941?language=java ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ์ฝ”๋“œ import java.util.Arrays; class Solution { public int solution(int []A, int []B) { int answer = 0; Arrays.sort(A); Arrays.sort(B); for(int i=0; i 2020. 3. 13.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - (Level2)N๊ฐœ์˜ ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜ https://programmers.co.kr/learn/courses/30/lessons/12953 ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ์ฝ”๋“œ class Solution { // ์ตœ๋Œ€ ๊ณต์•ฝ์ˆ˜ public int GCD(int a, int b){ if(a 2020. 3. 13.
๋ฐ˜์‘ํ˜•