2025/02/26 4

[프로그래머스] 가장 가까운 같은 글자

1. 내 풀이alphabet을 char로 해석해서, int값으로 내려놓으면 26개의 배열 내로 모든 알파벳이 어디에 있는지 인덱스를 알 수 있다.class Solution { public int[] solution(String s) { int[] alphabet = new int[26]; int[] answer = new int[s.length()]; for(int i = 0; i   2. 다른 분 풀이Map을 사용하셨다. map의 getOrDefault함수도 사용하셨다.원리는 같지만 훨씬 세련되게 풀었다. 보고 배워야지!import java.util.*;class Solution { public int[] solution(String s) ..

[프로그래머스] 시저 암호

https://school.programmers.co.kr/learn/courses/30/lessons/12926 1. 내 풀이StringBuilder를 이용해 효율성을 잡았다.아래 분의 풀이처럼 풀면 result += ~~ 할때마다 새로운 객체가 할당되어 메모리 낭비 & CPU 자원이 낭비될 수 있다. 이게 다 효율성에서 나중에 걸리니 미리미리 StringBuilder 사용하는 습관을 들여두는게 좋을 것 같다.class Solution { public String solution(String s, int n) { char[] chars = s.toCharArray(); StringBuilder sb = new StringBuilder(); for(int i =..

[프로그래머스] 이상한 문자 만들기

1. 내 코드StringBuilder를 통해 값 변경 가능한 곳으로 옮겨주고 쌩구현했다.나는 보통 쌩으로 구현하는 경우가 많은 것 같다. API를 좀 더 잘 이용하는 방법이 필요해보인다.class Solution { public String solution(String s) { StringBuilder sb = new StringBuilder(s); int wordIdx = 0; for(int i = 0; i= 'a' && ch = 'A' && ch      2. 다른 사람 코드공백이 여러 개일 수도 있다는 말에 번거로울 것 같다고 생각해서 split 하지 않았는데, 오히려 하니까 좋은 것 같다.그리고 공백에도 toLowerCase(), toUpperCase()..