JAVA_LeetCode 38_Count and Say 풀이 class Solution { public String countAndSay(int n) { // 1이면 1반환 if(n == 1) return "1"; // n - 1을 파라미터로 넣어서 string으로 초기화 String str = countAndSay(n - 1); StringBuilder sb = new StringBuilder(); int num = 0, len = str.length(), i = 0; char ch; // 받은 파라미터만큼 실행 while(num < len){ // 문자 초기화 ch = str.charAt(num); i = num + 1; // 조건에 부합하면 개수 증가(같은 문자 연속 체크) while(i < len && str.charAt(i) == ch) i++; // 개수 더하고, 해당 숫자 더해주기 sb.append(i - num); sb.append(ch); // 초기화 num = i;...
원문 링크 : JAVA_LeetCode 38_Count and Say