跳至主要内容

2259. Remove Digit From Number to Maximize Result

Hint

class Solution {
public:
string removeDigit(string number, char digit)
{
string res;
for (int i = 0; i < number.size(); i++)
{
if (number[i] == digit)
{
string temp = number.substr(0, i) + number.substr(i + 1, number.size());
res = max(res, temp);
}
}
return res;
}
};
  • T: O(n)O(n)
  • S: O(1)O(1)