프로그래머스(자바)/LV.1(자바)

    옹알이2 -> 포함하고 있지않다면 if !(babb.contains(text+text))★★

    class Solution { public int solution(String[] babbling) { int cnt = 0; for (String babb : babbling) { for (String text : new String[]{"aya", "ye", "woo", "ma"}) { if (!babb.contains(text + text)) { babb = babb.replace(text, " "); } } babb = babb.strip(); if (babb.length() == 0) { cnt++; } } return cnt; } } ▶ 향상된 for문을 for (String text : new String[]{"aya", "ye", "woo", "ma"}) 이렇게도 쓸수 있다는 사실에 주의 ..

    크레인 인형 뽑기 → 열접근<for each문 2개>★★+break문★

    나의 풀이 import java.util.*; class Solution { public int solution(int[][] boards, int[] moves) { Stack stack = new Stack(); int cnt = 0; // moves의 요소를 index로 활용하기 위해 각 요소에서 1씩 빼준다. for (int i = 0; i = 2 && stack.get..

    신규 아이디 추천→ 정규식★★ for java

    나의 풀이 public class Solution { public String solution(String new_id) { String answer = ""; //1단계 알파벳을 전부다 소문자로 바꾸어 준다. String tmp= new_id.toLowerCase(); //2단계 소문자, 숫자, -, _, . 을 제외한 모든 문자를 소거한다. tmp=tmp.replaceAll("[^a-z0-9\\-_.]", ""); //3단계 마침표가 2개이상인 경우 1개로 대체한다. tmp=tmp.replaceAll("\\.+", "."); //4단계 문자열이 마침표로 시작하거나 끝나는 경우에는 앞쪽의 마침표와 뒤쪽의 마침표를 제거해 준다. tmp=tmp.replaceAll("^[.]|[.]$", ""); //5단계..

    폰켓몬→ boxed()★+ collectingAndThen()

    나의 풀이 import java.util.*; class Solution { public int solution(int[] nums) { int choice_cnt = nums.length/2; Integer[] arr = Arrays.stream(nums).boxed().toArray(Integer[]::new); Set set = new HashSet(Arrays.asList(arr)); int kind_cnt=set.size(); if(choice_cnt>kind_cnt){ return kind_cnt; } else{ return choice_cnt; } } } 다른 사람의 풀이 import java.util.Arrays; import java.util.stream.Collectors; class ..