Day89

강태훈·2026년 5월 8일

nbcamp TIL

목록 보기
89/97

알고리즘 코드카타

Customers Who Bought All Products

select customer_id
from Customer
group by customer_id
having count(distinct product_key) >= (
    select count(distinct product_key) as count
    from Product
);

JadenCase 문자열 만들기

class Solution {
    public String solution(String s) {
        StringBuilder answer = new StringBuilder();

        String[] words = s.split(" ", -1);

        for (String word : words) {
            if(word.isEmpty()){
                answer.append(" ");
                continue;
            }

            if(word.charAt(0) == ' ' && word.length() > 1){
                int count = counting(word);

                String newW = Character.toUpperCase(word.charAt(count)) + word.substring(count + 1);

                for (int i = 0; i < count; i++) {
                    answer.append(" ");
                }

                answer.append(newW).append(" ");
            }else {
                String newWord = Character.toUpperCase(word.charAt(0)) + word.substring(1).toLowerCase();
                answer.append(newWord).append(" ");
            }
        }

        return answer.deleteCharAt(answer.length() - 1).toString();
    }

    public int counting(String word){
        int count = 0;

        char[] w = word.toCharArray();

        for (char c : w) {
            if(c == ' '){
                count++;
            }
        }

        return count;
    }
}

0개의 댓글