
점프와 순간 이동(Lv.2)[프로그래머스]
2022. 9. 16. 10:35
알고리즘
import java.util.*; public class Solution { public int solution(int n) { int battery = 0; int distance = n; while (distance>0){ if( distance%2 == 0){ distance = distance/2; }else { distance = (distance-1)/2; battery ++; } if (distance==0){ break; } } return battery; } }

올바른 괄호(Lv.2)[프로그래머스]
2022. 9. 16. 08:42
알고리즘
import java.util.*; class Solution { boolean solution(String s) { int cnt = 0; //괄호가 "()" 일 경우에만 허용이기에 시작과 끝이 ")", "(" 일 경우 false if (String.valueOf(s.charAt(0)).equals(")")||String.valueOf(s.charAt(s.length()-1)).equals("(")){ return false; } for (int i = 0; i < s.length(); i++) { //"(" 일 경우 +1 ")"일 경우 -1 if (String.valueOf(s.charAt(i)).equals("(")) { cnt +=1; } else { cnt -=1; } //"(()))()(()"..

JadenCase 문자열 만들기(Lv.2)[프로그래머스]
2022. 9. 15. 11:07
알고리즘
import java.util.*; class Solution { public String solution(String s) { StringBuilder answer = new StringBuilder(); List split = List.of(s.split("")); List changeLowerCase = new ArrayList(); //모든 글자 소문자로 변환 for (String change : split){ String lowerCase = change.toLowerCase(); changeLowerCase.add(lowerCase); } // i번째 인덱스가 " "이고 i+1번째 인덱스가 " "이 아닐경우 단어의 첫번째 글자이므로 대문자로 변환 for(int i= 0; i

[1차] 비밀지도(Lv.1)[프로그래머스 2018 KAKAO BLIND RECRUITMENT]
2022. 9. 14. 07:33
알고리즘
import java.util.*; class Solution { public List solution(int n, int[] arr1, int[] arr2) { //비밀지도1 List map1 =new ArrayList(); //비밀지도2 List map2 =new ArrayList(); //비밀지도 1+2 합친거 List secretMap = new ArrayList(); //1번지도 이진수로 변환하여 1일경우 # 0일경우 " "으로 for (int x : arr1){ String result = ""; int change = x; while (change>0){ if (change%2==1){ result+="#"; change = change /2; } else if (change%2==0) { ..

성격 유형 검사하기(Lv.1)[프로그래머스 2022 KAKAO TECH INTERNSHIP]
2022. 9. 6. 21:24
알고리즘
import java.util.*; class Solution { public String solution(String[] survey, int[] choices) { String answer = ""; HashMap mbti = new HashMap(); mbti.put("R",0); mbti.put("T",0); mbti.put("C",0); mbti.put("F",0); mbti.put("J",0); mbti.put("M",0); mbti.put("A",0); mbti.put("N",0); int[] scoreBoard = new int[]{3,2,1,0,1,2,3}; for (int i = 0; i< choices.length; i++){ //인덱스는 0번 부터 시작하니 설문지에서 선택한 번호 -..

신규 아이디 추천(Lv.1)[프로그래머스 2021 KAKAO BLIND RECRUITMENT]
2022. 9. 6. 00:29
알고리즘
import java.util.*; class Solution { public String solution(String new_id) { String answer = ""; //Step1 소문자 변환 String stepOne = new_id.toLowerCase(); //Step2 허용되는 특수문자 외 모두 제거 String change = stepOne.replaceAll("[^a-z0-9._-]",""); String[] arr = change.split(""); List stepTwo = new ArrayList(Arrays.asList(arr)); //Step3 연속 . 제거 List stepThree = stepTwo; List stepFour = new ArrayList(); for (int..

같은 숫자는 싫어(Lv.1)[프로그래머스]
2022. 8. 31. 18:29
알고리즘
import java.util.*; public class Solution { public List solution(int []arr) { List x = new ArrayList(); for(int i = 0; i< arr.length-1; i++){ if (arr[i]!=arr[i+1]){ x.add(arr[i]); } } x.add(arr[arr.length-1]); return x; } }

나머지가 1이 되는 수 찾기(Lv.1)[프로그래머스]
2022. 8. 31. 18:27
알고리즘
class Solution { public int solution(int n) { int answer = 0; for(int i = 1; i