코딩테스트 풀이/JAVA
[LeetCode/Easy] 2710. Remove Trailing Zeros From a String
무지맘
2023. 6. 30. 21:48
1. Input
1) String num
2. Output
1) num에서 후행 0을 뺀 결과를 반환
3. Constraint
1) 1 <= num.length <= 1000
2) num은 숫자로만 이루어져 있다.
3) num에 선행 0은 없다.
4. Example
Input: num = "51230100" -> Output: "512301"
Input: num = "123" -> Output: "123"
5. Code
class Solution {
public String removeTrailingZeros(String num) {
int i = num.length()-1;
while(num.charAt(i)=='0') i--;
return num.substring(0,i+1);
}
}
- 100%, 94%