How to get the least number after deleting k digits from the input number

前端 未结 11 1206
灰色年华
灰色年华 2020-12-11 05:34

For example, if the input number is 24635, the least number is 23 after deleting any 3 digits.

It\'s not the same as taking the two smalles

11条回答
  •  攒了一身酷
    2020-12-11 05:52

    The idea is to traverse through the string from the beginning and remove the first digit which is greater than the digit following it. If no such digit exists, remove the last digit.

        class Solution {
        private:
            void removeOneDigit(string& s){
                for(int i=0; i

提交回复
热议问题