class Solution { public long[] solution(int x, int n) { long[] answer = new long[n]; long temp = x; int index = 0; while (index != n) { answer[index] = temp; index++; temp += x; } return answer; } } - 성공 - for문보다 while 문 생각이 먼저나서 while문으로 풀었음 class Solution { public long[] solution(long x, int n) { long[] answer = new long[n]; for(int i = 0; i < n; i++){ answer[i] = x * (i + 1); } return answer;..
class Solution { public boolean solution(int x) { int sum = 0; char[] chars = String.valueOf(x).toCharArray(); for (char c : chars) { sum += c - '0'; } return x % sum == 0; } } - 성공 - char 타입으로 바꿔서 풀이 class Solution { public boolean solution(int x) { int mod = x; int sum = 0; do { sum += (mod % 10); mod /= 10; } while(mod % 10 > 0); return x % sum == 0; } } - 다른 사람 풀이 - 숫자 자체로 각 자릿수를 뽑아서 합을 구함
class Solution { public int solution(double num) { int answer = 0; if (num == 1) return 0; while (num != 1) { if (num%2 == 0) { num /= 2; } else { num = num * 3 + 1; } answer ++; if (answer == 500) return -1; } return answer; } } - 성공 - num 1일때 체크 - 들어오는 타입 double로 바꾸기
class Solution { public int[] solution(int n, int m) { int big = Math.max(n, m); int small = Math.min(n, m); return new int[]{ gcd(big, small), lcm(big, small)}; } public static int gcd(int big, int small) { return big % small == 0 ? small : gcd(small,big % small); } public static int lcm(int big, int small) { return big * small / gcd(big, small); } } - 성공 - 예전에 최대공약수 구하는 gcd 함수를 보고 외워져서 사용했음 - ..
class Solution { public long solution(long n) { double sqrt = Math.sqrt(n); long answer = sqrt%1 == 0 ? (long)((sqrt+1) * (sqrt+1)) : -1; return answer; } } - 성공 - pow, sqrt 메소드가 생각남 - 1로 나눈 나머지가 0으로 떨어지지않으면 제곱근이 아닌것을 활용함 class Solution { public long solution(long n) { if (Math.pow((int)Math.sqrt(n), 2) == n) { return (long) Math.pow(Math.sqrt(n) + 1, 2); } return -1; } } - 다른 사람 풀이 - sqrt한 값을 다..
import java.util.ArrayList; class Solution { public int[] solution(int[] arr) { ArrayList list = new ArrayList(); if (arr.length == 1) { return new int[]{-1}; } for (int i = 0; i < arr.length ; i++) { list.add(arr[i]); } int min = Integer.MAX_VALUE; int index = 0; for (int i = 0; i < arr.length; i++) { if (arr[i] < min) { min = arr[i]; index = i; } } list.remove(index); int[] answer = new int[ar..
class Solution { public String solution(String s) { String answer = ""; int cnt = 0; String[] array = s.split(""); for(String ss : array) { cnt = ss.contains(" ") ? 0 : cnt + 1; answer += cnt%2 == 0 ? ss.toLowerCase() : ss.toUpperCase(); } return answer; } } - 실패 - 처음에 제출했는데 계속 몇몇 케이스에서 실패 - 이유를 몰라서 찾아보니 문제 자체를 잘못이해하고 풀었음 - 나는 그냥 문자를 공백 기준으로 쪼개서 풀었는데 문제에서 각 단어는 하나 이상의 공백문자로 구분되어 있습니다. 라는 말이 있다.
import java.util.Stack; class Solution { public int solution(int[][] board, int[] moves) { int answer = 0; Stack basket = new Stack(); for (int move : moves) { for (int i = 0; i < board.length; i++) { if (board[i][move-1] != 0) { if (basket.isEmpty() || basket.peek() != board[i][move-1]) { basket.push(board[i][move-1]); } else if (basket.peek() == board[i][move-1]) { basket.pop(); answer += 2; }..
- Total
- Today
- Yesterday
- 패스트캠퍼스 컴퓨터공학 완주반
- http
- 백기선 스터디
- dreamcoding
- JPA 연관관계 매핑
- 이펙티브자바
- 김영한 JPA
- js array
- 이펙티브자바 아이템59
- js api
- JS 딥다이브
- 집 구하기
- HTTP 완벽 가이드
- 이펙티브자바 스터디
- 가상 면접 사례로 배우는 대규모 시스템 설계 기초
- 모던자바스크립트
- 킹수빈닷컴
- 이펙티브자바 아이템60
- 드림코딩
- 프로그래머스
- BOJ
- GCP
- java
- Spring Security
- REST API
- 김영한 http
- 백준
- HTTP 완벽가이드
- js promise
- 프로그래머스 SQL
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |