본문 바로가기

전체 글88

키패드 누르기 풀이 class Solution { public String solution(int[] numbers, String hand) { StringBuilder sb = new StringBuilder(); int left = 10; int right = 12; for (int i = 0; i < numbers.length; i++) { int n = numbers[i]; if (n == 1 || n == 4 || n == 7) { left = n; sb.append("L"); } if (n == 3 || n == 6 || n == 9) { right = n; sb.append("R"); } if (n == 2 || n == 5 || n == 8 || n == 0) { if( n == 0 ) n = 11; i..
두 개 뽑아서 더하기 풀이 import java.util.*; class Solution { public int[] solution(int[] numbers) { ArrayList list = new ArrayList(); for (int i = 0; i < numbers.length - 1; i++) { for (int j = i + 1; j < numbers.length; j++) { int sum = numbers[i] + numbers[j]; if (!list.contains(sum)) { list.add(sum); } } } Collections.sort(list); int[] answer = new int[list.size()]; for (int k = 0; k < list.size(); k++) { answer[..
3진법 뒤집기 풀이 class Solution { public int solution(int n) { int answer = 0; String t = Integer.toString(n, 3); String s =""; for(int i=t.length()-1; i>=0; i--){ s += t.charAt(i); } answer = Integer.parseInt(s, 3); return answer; } } 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr Integer.toString(숫자, 바꾸고 싶은 진법수) 를 처음 배웠다!
내적 풀이 class Solution { public int solution(int[] a, int[] b) { int answer = 0; for(int i=0; i
신규 아이디 추천 풀이 import java.util.*; class Solution { public String solution(String new_id) { String a = ""; new_id = new_id.toLowerCase(); //1단계 for (int i = 0; i = 'a' && c = '0' && c 0 && a.charAt(0) == '.') { a = a.substring(1); } //4단계 if (a.length() > 0 && a.charAt(a.length() - 1) == '.') { a = a.substring(0, a.length() - 1); } //4단계 추가작업 if (..
음양 더하기 풀이 class Solution { public int solution(int[] absolutes, boolean[] signs) { int answer = 0; for(int i=0; i