Day80

강태훈·2026년 4월 24일

nbcamp TIL

목록 보기
80/97

알고리즘 코드카타

Monthly Transactions I

select date_format(trans_date, "%Y-%m") as month, country, count(id) as trans_count, 
    sum(case when state = "approved" then 1 else 0 end) as approved_count, 
    sum(amount) as trans_total_amount, 
    sum(case when state = "declined" then 0 else amount end) as approved_total_amount
from Transactions
group by year(trans_date), month(trans_date), country;

둘만의 암호

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Solution {
    public String solution(String s, String skip, int index) {
        String answer = "";

        char[] chars = s.toCharArray();
        List<Character> list = skiplist(skip);

        int index2 = index;
        if(index2 >= list.size()) {
             index2 = index - list.size();
        }

        for(char c:chars){
            int i = Arrays.binarySearch(list.toArray(), c);
            if(i + index2 >= list.size()){

                answer += list.get(i + index2 - list.size());
            }else{
                answer += list.get(i + index2);
            }
        }

        return answer;
    }
    private List<Character> skiplist(String skips){
        char[] alpha = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
        List<Character> alphaskip = new ArrayList<>();
        for(char a:alpha){
            alphaskip.add(a);
        }

        for(char skip: skips.toCharArray()){
            int i = Arrays.binarySearch(alphaskip.toArray(), skip);
            alphaskip.remove(i);
        }

        return alphaskip;
    }
}

0개의 댓글