본문 바로가기 메뉴 바로가기

kingsubin

프로필사진
  • 글쓰기
  • 관리
  • 태그
  • 방명록
  • RSS

kingsubin

검색하기 폼
  • 분류 전체보기 (485)
    • Python (1)
    • Java (35)
    • Spring (18)
    • JavaScript & TypeScript (23)
    • HTML & CSS (2)
    • Database (4)
    • DevOps (8)
    • CS (13)
    • Algorithm (10)
    • etc (22)
    • PS (231)
      • boj (157)
      • programmers (54)
      • etc (19)
      • leetcode (1)
    • 책 (98)
      • 이펙티브자바 (50)
      • 모던 자바스크립트 딥다이브 (24)
      • misc (14)
      • 독서 (10)
    • 일상 (20)
  • 방명록

PS/programmers (54)
Level1) x만큼 간격이 있는 n개의 숫자

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;..

PS/programmers 2020. 9. 12. 03:25
Level1) 하샤드 수

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; } } - 다른 사람 풀이 - 숫자 자체로 각 자릿수를 뽑아서 합을 구함

PS/programmers 2020. 9. 12. 03:13
Level1) 콜라츠 추측

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로 바꾸기

PS/programmers 2020. 9. 12. 02:52
Level1) 최대공약수와 최소공배수

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 함수를 보고 외워져서 사용했음 - ..

PS/programmers 2020. 9. 12. 01:12
Level1) 정수 제곱근 판별

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한 값을 다..

PS/programmers 2020. 9. 12. 00:40
Level1) 제일 작은 수 제거하기

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..

PS/programmers 2020. 9. 12. 00:29
Level1) 이상한 문자 만들기

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; } } - 실패 - 처음에 제출했는데 계속 몇몇 케이스에서 실패 - 이유를 몰라서 찾아보니 문제 자체를 잘못이해하고 풀었음 - 나는 그냥 문자를 공백 기준으로 쪼개서 풀었는데 문제에서 각 단어는 하나 이상의 공백문자로 구분되어 있습니다. 라는 말이 있다.

PS/programmers 2020. 9. 11. 18:42
Level1) 크레인 인형뽑기 게임

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; }..

PS/programmers 2020. 9. 11. 16:45
이전 1 2 3 4 5 6 7 다음
이전 다음
링크
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
TAG
  • 패스트캠퍼스 컴퓨터공학 완주반
  • http
  • 백기선 스터디
  • dreamcoding
  • JPA 연관관계 매핑
  • 이펙티브자바
  • 김영한 JPA
  • js array
  • 이펙티브자바 아이템59
  • js api
  • JS 딥다이브
  • 집 구하기
  • HTTP 완벽 가이드
  • 이펙티브자바 스터디
  • 가상 면접 사례로 배우는 대규모 시스템 설계 기초
  • 모던자바스크립트
  • 킹수빈닷컴
  • 이펙티브자바 아이템60
  • 드림코딩
  • 프로그래머스
  • BOJ
  • GCP
  • java
  • Spring Security
  • REST API
  • 김영한 http
  • 백준
  • HTTP 완벽가이드
  • js promise
  • 프로그래머스 SQL
more
«   2023/12   »
일 월 화 수 목 금 토
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
글 보관함

Blog is powered by Tistory / Designed by Tistory

티스토리툴바