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

Algorithm242

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[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.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - (Level2)ํฐ์ผ“๋ชฌ https://programmers.co.kr/learn/courses/30/lessons/1845?language=java ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ์ฝ”๋“œ import java.util.*; class Solution { public int solution(int[] nums) { int answer = 0; List list = new ArrayList(); list.add(nums[0]); // nums[] ๋ฐฐ์—ด์˜ ์ค‘๋ณต์ œ๊ฑฐ for(int i=1; i ๊ฐ€์งˆ ์ˆ˜ ์žˆ๋Š” ์ข…๋ฅ˜๋Š” ํ•œ๊ฐ€์ง€ 3)์˜ ๊ฒฝ์šฐ, ์ค‘๋ณต์„ ์ œ๊ฑฐํ•˜๊ณ  ๋‚˜๋ฉด [1, 2, 3,.. 2020. 3. 13.
ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค[Java] - (Level2)๋‹ค์Œ ํฐ ์ˆซ์ž https://programmers.co.kr/learn/courses/30/lessons/12911?language=java ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค ์ฝ”๋“œ ์ค‘์‹ฌ์˜ ๊ฐœ๋ฐœ์ž ์ฑ„์šฉ. ์Šคํƒ ๊ธฐ๋ฐ˜์˜ ํฌ์ง€์…˜ ๋งค์นญ. ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์˜ ๊ฐœ๋ฐœ์ž ๋งž์ถคํ˜• ํ”„๋กœํ•„์„ ๋“ฑ๋กํ•˜๊ณ , ๋‚˜์™€ ๊ธฐ์ˆ  ๊ถํ•ฉ์ด ์ž˜ ๋งž๋Š” ๊ธฐ์—…๋“ค์„ ๋งค์นญ ๋ฐ›์œผ์„ธ์š”. programmers.co.kr ์ฝ”๋“œ class Solution { // n์„ 2์ง„์ˆ˜๋กœ ๋ณ€ํ™˜ํ–ˆ์„ ๋•Œ 1์˜ ๊ฐฏ์ˆ˜ ์ฐพ๊ธฐ public static int oneNum(int num) { int count = 0; while(num != 0) { if(num%2 != 0) count ++; num /= 2; } return count; } public int solution(int n) { int answer = 0; fo.. 2020. 3. 13.
๋ฐ˜์‘ํ˜•