File tree 2 files changed +15
-1
lines changed
2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change 826
826
| 2696 | [Minimum String Length After Removing Substrings](https://leetcode.com/problems/minimum-string-length-after-removing-substrings) | [](src/MinimumStringLengthAfterRemovingSubstrings.java) | |
827
827
| 2697 | [Lexicographically Smallest Palindrome](https://leetcode.com/problems/lexicographically-smallest-palindrome) | [](src/LexicographicallySmallestPalindrome.java) | |
828
828
| 2706 | [Buy Two Chocolates](https://leetcode.com/problems/buy-two-chocolates) | [](src/BuyTwoChocolates.java) | |
829
- | 2710 | [Remove Trailing Zeros From a String](https://leetcode.com/problems/remove-trailing-zeros-from-a-string) | | |
829
+ | 2710 | [Remove Trailing Zeros From a String](https://leetcode.com/problems/remove-trailing-zeros-from-a-string) | [](src/RemoveTrailingZerosFromAString.java) | |
830
830
| 2716 | [Minimize String Length](https://leetcode.com/problems/minimize-string-length) | | |
831
831
| 2717 | [Semi-Ordered Permutation](https://leetcode.com/problems/semi-ordered-permutation) | | |
832
832
| 2728 | [Count Houses in a Circular Street](https://leetcode.com/problems/count-houses-in-a-circular-street) | | |
Original file line number Diff line number Diff line change
1
+ // https://leetcode.com/problems/remove-trailing-zeros-from-a-string
2
+ // T: O(|s|)
3
+ // S: O(|s|)
4
+
5
+ public class RemoveTrailingZerosFromAString {
6
+ public String removeTrailingZeros (String num ) {
7
+ for (int i = num .length () - 1 ; i >= 0 ; i --) {
8
+ if (num .charAt (i ) != '0' ) {
9
+ return num .substring (0 , i + 1 );
10
+ }
11
+ }
12
+ return "" ;
13
+ }
14
+ }
You can’t perform that action at this time.
0 commit comments