# 2259. Remove Digit From Number to Maximize Result ###### tags: `Leetcode` `Easy` `Microsoft` Link: https://leetcode.com/problems/remove-digit-from-number-to-maximize-result/ ## 思路 check the next digit we can just remove the **leftmost** digit if it's followed by a larger number. If we cannot find such case, we remove the last occurence of digit. ## Code ```java= class Solution { public String removeDigit(String number, char digit) { char[] digits = number.toCharArray(); int lastDig = 0; for(int i = 0;i < digits.length;i++){ if(digits[i]==digit){ lastDig = i; if(i+1==digits.length || digits[i+1]>digits[i]){ return number.substring(0, i) + number.substring(i+1); } } } return number.substring(0,lastDig) + number.substring(lastDig+1); } } ```