Leetcode Note: Go - Remove Digit From Number to Maximize Result

Remove Digit From Number to Maximize Result - LeetCode
https://leetcode.com/problems/remove-digit-from-number-to-maximize-result/

  • Go 言語で取り組んだメモ

回答

Funny Go solution - Remove Digit From Number to Maximize Result - LeetCode
https://leetcode.com/problems/remove-digit-from-number-to-maximize-result/solutions/2462835/funny-go-solution/

func removeDigit(number string, digit byte) string {
    var res string
    
    for i := 0; i < len(number); i++ {
        if number[i] == digit {
            if res == "" || number[:i] + number[i+1:] > res {
                res = number[:i] + number[i+1:]
            }
        }
    }
    
    return res
}