Shawn's Blog

  • Home
  • Tags
  • Categories
  • Archives
  • Search
  • Table of Contents
  • Overview

Shawn

若有恒,何必三更眠五更起;最无益,莫过一日曝十日寒。
392 posts
13 categories
114 tags

LeetCode 1903. Largest Odd Number in String

Posted on 2021-06-20 Edited on 2024-11-24 In LeetCode
1
2
3
4
5
6
7
8
9
10
11
12
class Solution {
public:
string largestOddNumber(string num) {
const int n = num.size();
int i = n - 1;
for(; i >= 0; --i) {
// if ((num[i] - '0') & 1) break;
if (num[i] & 1) break; // ASCII code of an odd/even is also an odd/even.
}
return num.substr(0, i + 1);
}
};
# Greedy
LeetCode 1904. The Number of Full Rounds You Have Played
AcWing 3696. 构造有向无环图
© 2024 Shawn
Powered by Hexo & NexT.Mist
0%