TIL(Today I Learned)_데일리루틴_24.12.10.Tue

728x90

데일리루틴 SQL

MySQL 우유와 요거트가 담긴 장바구니 정답입니다.

SELECT
    CART_ID
FROM
    CART_PRODUCTS
WHERE
    NAME = 'Milk'
    AND CART_ID IN (
    SELECT
        CART_ID
    FROM
        CART_PRODUCTS
    WHERE NAME = 'Yogurt'
    )
ORDER BY
    CART_ID;

데일리루틴 알고리즘

Java 문자열 나누기 정답입니다.

class Solution {
    public int solution(String s) {
        int answer = 0;
        int countX = 0;
        int countOther = 0;
        char x = 0;
        
        for (int i = 0; i < s.length(); i++) {
            if(countX == 0 && countOther == 0) {
                x = s.charAt(i);
                countX++;
            } else {
                if (s.charAt(i) == x) {
                    countX++;
                } else {
                    countOther++;
                }
            }
            
            if (countX == countOther) {
                answer++;
                countX = 0;
                countOther = 0;
            }
        }
        
        if (countX != 0 || countOther != 0) {
            answer ++;
        }
        
        return answer;
    }
}
728x90
반응형
LIST