1903. Largest Odd Number In String
https://leetcode.com/problems/largest-odd-number-in-string
突然想到該來寫一下
不過這題也太簡單
題目:
給一個string是某個數字,找一個substring會是最大的奇數數字。
如果找不到就回傳空字串。
解法:
從string最後面往前找,如果那個數字是奇數 加上前面所有奇數就會是最大。
直接greedy,去找就行,因為找出來的一定位數最多,保證是最大的奇數。
Code:
class Solution {
public:
string largestOddNumber(string num) {
for (int i = num.size()-1; i >= 0; i