ALGORITHM ๐Ÿค–/Programmers

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค
[level 1] ํ•˜์ƒค๋“œ ์ˆ˜ - 12947 ๋ฌธ์ œ ๋งํฌ ์„ฑ๋Šฅ ์š”์•ฝ ๋ฉ”๋ชจ๋ฆฌ: 75.6 MB, ์‹œ๊ฐ„: 0.11 ms ๊ตฌ๋ถ„ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต > ์—ฐ์Šต๋ฌธ์ œ ์ฑ„์ ๊ฒฐ๊ณผ Empty ๋ฌธ์ œ ์„ค๋ช… ์–‘์˜ ์ •์ˆ˜ x๊ฐ€ ํ•˜์ƒค๋“œ ์ˆ˜์ด๋ ค๋ฉด x์˜ ์ž๋ฆฟ์ˆ˜์˜ ํ•ฉ์œผ๋กœ x๊ฐ€ ๋‚˜๋ˆ„์–ด์ ธ์•ผ ํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด 18์˜ ์ž๋ฆฟ์ˆ˜ ํ•ฉ์€ 1+8=9์ด๊ณ , 18์€ 9๋กœ ๋‚˜๋ˆ„์–ด ๋–จ์–ด์ง€๋ฏ€๋กœ 18์€ ํ•˜์ƒค๋“œ ์ˆ˜์ž…๋‹ˆ๋‹ค. ์ž์—ฐ์ˆ˜ x๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ x๊ฐ€ ํ•˜์ƒค๋“œ ์ˆ˜์ธ์ง€ ์•„๋‹Œ์ง€ ๊ฒ€์‚ฌํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•ด์ฃผ์„ธ์š”. ์ œํ•œ ์กฐ๊ฑด x๋Š” 1 ์ด์ƒ, 10000 ์ดํ•˜์ธ ์ •์ˆ˜์ž…๋‹ˆ๋‹ค. ์ž…์ถœ๋ ฅ ์˜ˆ x return 10 true 12 true 11 false 13 false ์ž…์ถœ๋ ฅ ์˜ˆ ์„ค๋ช… ์ž…์ถœ๋ ฅ ์˜ˆ #1 10์˜ ๋ชจ๋“  ์ž๋ฆฟ์ˆ˜์˜ ํ•ฉ์€ 1์ž…๋‹ˆ๋‹ค. 10์€ 1๋กœ ๋‚˜๋ˆ„์–ด ๋–จ์–ด์ง€๋ฏ€๋กœ 10์€ ํ•˜์ƒค๋“œ ..
https://school.programmers.co.kr/learn/courses/30/lessons/160586 import java.util.*; class Solution { public int[] solution(String[] keymap, String[] targets) { int[] answer = new int[targets.length]; Map pressCount = new HashMap(); // key: ๋ฌธ์ž, value: ์ตœ์†Œ ์ž…๋ ฅ ํšŸ์ˆ˜ for (String key : keymap) { // ๊ฐ ๋ฌธ์ž๋ฅผ ์ž…๋ ฅํ•˜๊ธฐ ์œ„ํ•ด ํ‚ค๋ฅผ ๋ˆ„๋ฅด๋Š” ์ตœ์†Œ ํšŸ์ˆ˜๋ฅผ ๋งต์— ์ €์žฅ for (int i = 0; i < key.length(); i++) { char ch = key.charAt(i); if (!p..
https://school.programmers.co.kr/learn/courses/30/lessons/42586 import java.util.*; class Solution { public int[] solution(int[] progresses, int[] speeds) { int[] day = new int[progresses.length]; Queue queue = new LinkedList(); List answer = new ArrayList(); for (int i = 0; i < progresses.length; i++) { int temp = progresses[i]; while (temp < 100) { temp += speeds[i]; day[i] += 1; } queue.add(d..
https://school.programmers.co.kr/learn/courses/30/lessons/42889 import java.util.*; class Solution { public int[] solution(int N, int[] stages) { Map map = new HashMap(); for (int i = 1; i = i) { all++; if (j == i) { fail++; } } } double per = (double) fail / all; // ์‹คํŒจ์œจ if(fail == 0 && all == 0) { // ๋ชจ๋“  ์‚ฌ๋žŒ๋“ค์ด ์‹œ๋„์กฐ์ฐจ ๋ชปํ•œ ์Šคํ…Œ์ด์ง€๊ฐ€ ์žˆ์„ ๋•Œ๋Š” 0์œผ๋กœ ์ฒ˜๋ฆฌ (0 / 0 = NaN ๋ฐฉ์ง€) per = 0; } map.put(i, per); // key: ์Šคํ…Œ์ด์ง€, v..
https://school.programmers.co.kr/learn/courses/30/lessons/42840 import java.util.*; class Solution { public int[] solution(int[] answers) { int[] supoza1 = {1, 2, 3, 4, 5}; int[] supoza2 = {2, 1, 2, 3, 2, 4, 2, 5}; int[] supoza3 = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5}; int[] score = new int[3]; int a = 1; int temp = 0; for (int k : answers) { // ์ˆ˜ํฌ์ž1 ์ ์ˆ˜ ๊ตฌํ•˜๊ธฐ if (supoza1[temp] == k) { score[0] += a; } te..
https://school.programmers.co.kr/learn/courses/30/lessons/176963 class Solution { public int[] solution(String[] name, int[] yearning, String[][] photo) { int[] answer = new int[photo.length]; for (int i = 0; i < photo.length; i++) { for (int j = 0; j < photo[i].length; j++) { for (int k = 0; k < name.length; k++) { if (name[k].equals(photo[i][j])) { answer[i] += yearning[k]; } } } } return answ..
https://school.programmers.co.kr/learn/courses/30/lessons/17681 class Solution { public String[] solution(int n, int[] arr1, int[] arr2) { String[] answer = new String[n]; for(int i = 0; i ๊ณต๋ฐฑ' ๋ณ€ํ™˜ answer[i] = answer[i].replace("1", "#"); // '1 -> #'' ๋ณ€ํ™˜ while (answer[i]...
daxx0ne
'ALGORITHM ๐Ÿค–/Programmers' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๊ธ€ ๋ชฉ๋ก