Algorithm277 [Programmers] Lv.0 / 문자열안에 문자열 / Java 문제 풀이class Solution { public int solution(String str1, String str2) { return str1.contains(str2) ? 1 : 2; }} 출처https://school.programmers.co.kr/learn/courses/30/lessons/120908 2024. 5. 2. [Programmers] Lv.0 / 제곱수 판별하기 / Java 문제 풀이 class Solution { public int solution(int n) { return isPerfectSquare(n) ? 1 : 2; } private boolean isPerfectSquare(int num) { int sqrt = (int) Math.sqrt(num); return sqrt * sqrt == num; } } class Solution { public int solution(int n) { return (n % Math.sqrt(n) == 0) ? 1 : 2; } } 출처 https://school.programmers.co.kr/learn/courses/30/lessons/120909 2024. 4. 24. [Programmers] Lv.0 / 세균 증식 / Java 문제 풀이 class Solution { public int solution(int n, int t) { return n * (int) Math.pow((double) 2, (double) t); } } class Solution { public int solution(int n, int t) { for(int i = 0; i < t; i++) { n *= 2; } return n; } } class Solution { public int solution(int n, int t) { // 비트 연산자를 사용하여 정수 n을 t번 왼쪽으로 시프트(shift)한 후 결과를 반환 int answer = n 2024. 4. 24. [Programmers] Lv.0 / 문자열 정렬하기 (2) / Java 문제 풀이 import java.util.Arrays; class Solution { public String solution(String my_string) { String lower_case = my_string.toLowerCase(); char[] char_array = lower_case.toCharArray(); Arrays.sort(char_array); return new String(char_array); } } 출처 https://school.programmers.co.kr/learn/courses/30/lessons/120911 2024. 4. 24. [Programmers] Lv.0 / 7의 개수 / Java 문제 풀이 import java.util.Arrays; class Solution { public int solution(int[] array) { int count = 0; for (int num : array) { while (num > 0) { if (num % 10 == 7) { count++; } num /= 10; } } return count; } } 출처 https://school.programmers.co.kr/learn/courses/30/lessons/120912 2024. 3. 25. [Programmers] Lv.0 / 잘라서 배열로 저장하기 / Java 문제 풀이 import java.util.ArrayList; import java.util.List; class Solution { public String[] solution(String my_str, int n) { List resultList = new ArrayList(); int length = my_str.length(); for(int i = 0; i < length; i += n) { resultList.add(my_str.substring(i, Math.min(i + n, length))); } return resultList.toArray(new String[0]); } } 출처 https://school.programmers.co.kr/learn/courses/30/lessons/12.. 2024. 3. 20. [Programmers] Lv.0 / 문자열 밀기 / Java 문제 풀이 class Solution { public int solution(String A, String B) { if(A.equals(B)) { return 0; } int length = A.length(); for(int i = 0; i < length; i++) { A = A.charAt(length - 1) + A.substring(0, length - 1); if(A.equals(B)) { return i + 1; } } return -1; } } class Solution { public int solution(String A, String B) { String tempB = B.repeat(3); return tempB.indexOf(A); } } class Solution { publi.. 2024. 3. 20. [Programmers] Lv.0 / 종이 자르기 / Java 문제 풀이 class Solution { public int solution(int M, int N) { int horizontalCuts = M - 1; int verticalCuts = M * (N - 1); return horizontalCuts + verticalCuts; } } class Solution { public int solution(int M, int N) { return M * N - 1; } } 출처 https://school.programmers.co.kr/learn/courses/30/lessons/120922 2024. 3. 20. [Programmers] Lv.0 / 연속된 수의 합 / Java 문제 풀이 class Solution { public int[] solution(int num, int total) { int first = (total - (num * (num - 1) / 2)) / num; int[] result = new int[num]; for(int i = 0; i < num; i++) { result[i] = first + i; } return result; } } 출처 https://school.programmers.co.kr/learn/courses/30/lessons/120923 2024. 3. 19. [Programmers] Lv.0 / 다음에 올 숫자 / Java 문제 풀이 class Solution { public int solution(int[] common) { int n = common.length; int commonDifferenceOrRatio = common[1] - common[0]; if (common[n - 1] - common[n - 2] == commonDifferenceOrRatio) { return common[n - 1] + commonDifferenceOrRatio; } else { int ratio = common[n - 1] / common[n - 2]; return common[n - 1] * ratio; } } } class Solution { public int solution(int[] common) { int answer.. 2024. 3. 19. [Programmers] Lv.0 / 옹알이 (1) / Java 문제 풀이 import java.util.*; class Solution { public int solution(String[] babbling) { int count = 0; for (String word : babbling) { if (isPossible(word)) count++; } return count; } private boolean isPossible(String word) { if (word.equals("")) return true; if (word.startsWith("aya")) return isPossible(word.substring(3)); if (word.startsWith("ye")) return isPossible(word.substring(2)); if (word.sta.. 2024. 3. 18. [Programmers] Lv.0 / 이차원 배열 대각선 순회하기 / Java 문제 풀이 class Solution { public int solution(int[][] board, int k) { int sum = 0; for(int i = 0; i < board.length; i++) { for(int j = 0; j < board[0].length; j++) { if(i + j 2024. 3. 15. 이전 1 ··· 3 4 5 6 7 8 9 ··· 24 다음