https://school.programmers.co.kr/learn/courses/30/lessons/120812 class Solution { public int solution(int[] array) { int answer = 0; // ์ต๋น๊ฐ int max = Integer.MIN_VALUE; // ์ต๋๊ฐ ์ ์ฅ int[] index = new int[1001]; // ์ธ๋ฑ์ค ์นด์ดํ
for (int j : array) { index[j]++; // ๊ฐ์ ์ธ์ ์ธ๋ฑ์ค ๋ฐฐ์ด์ ์นด์ดํ
๊ฒฐ๊ณผ ๋ฐ์ } for(int i = 0; i < index.length; i++){ if(max < index[i]){ max = index[i]; // ๊ฐ์ฅ ๋ง์ด ์นด์ดํ
๋ ์๊ฐ ์ต๋น๊ฐ answer = i; } } int..
ALGORITHM ๐ค
์๊ณ ๋ฆฌ์ฆ ์ฐ์ต / ์ฝ๋ฉํ ์คํธ ์ค๋นhttps://school.programmers.co.kr/learn/courses/30/lessons/120906 class Solution { public int solution(int n) { int answer = 0; String str = n + ""; // ๋ฌธ์์ด๋ก ๋ณํ for(int i = 0; i < str.length(); i++){ char c = str.charAt(i); // ๋ฌธ์ ํ๋์ฉ ์๋ผ์ answer += Character.getNumericValue(c); // ์ ์๋ก ๋ณํํด์ค ๋ค์ ๋ํ๊ธฐ } return answer; } }
https://school.programmers.co.kr/learn/courses/30/lessons/120818 class Solution { public int solution(int price) { if(100000
https://school.programmers.co.kr/learn/courses/30/lessons/120898 class Solution { public int solution(String message) { int answer = message.length(); // ๋ฉ์ธ์ง ๊ธ์ ์ return answer*2; // ํ ๊ธ์ ๋น 2cm ์ด๋ฏ๋ก ๊ธ์์์ 2๋ฅผ ๊ณฑํด์ค } }
https://school.programmers.co.kr/learn/courses/30/lessons/120889 import java.util.Arrays; class Solution { public int solution(int[] sides) { Arrays.sort(sides); // ์ค๋ฆ์ฐจ์ ์ ๋ ฌ if(sides[0]+sides[1] > sides[2]){ // ๊ฐ์ฅ ๊ธด ๋ณ์ ๊ธธ์ด๊ฐ ๋ค๋ฅธ ๋ ๋ณ์ ๊ธธ์ด์ ํฉ๋ณด๋ค ์์ ๋ return 1; // 1 ์ถ๋ ฅ (์ผ๊ฐํ ๋ง๋ค ์ ์์) } else{ // ๊ทธ๋ ์ง ์์ผ๋ฉด return 2; // 2 ์ถ๋ ฅ (์ผ๊ฐํ ๋ง๋ค ์ ์์) } } }
https://school.programmers.co.kr/learn/courses/30/lessons/120819 class Solution { public int[] solution(int money) { int[] answer = new int[2]; answer[0] = money / 5500; answer[1] = money % 5500; return answer; } }