포스트

0 떼기

https://school.programmers.co.kr/learn/courses/30/lessons/181847

문제

  • 문제 풀이
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public class Solution {
    public String solution(String n_str) {
        int index = 0;
        // 문자열의 왼쪽부터 연속된 0을 찾아 인덱스를 업데이트한다.
        while (index < n_str.length() && n_str.charAt(index) == '0') {
            index++;
        }
        // 인덱스 이후의 문자열을 반환한다.
        return n_str.substring(index);
    }

    public static void main(String[] args) {
        Solution sol = new Solution();
        System.out.println(sol.solution("0010"));   // 출력: "10"
        System.out.println(sol.solution("854020")); // 출력: "854020"
    }
}
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.