classSolution { public: // 范围比较法 intsecondHighest1(string s){ int first = -1,second = -1; for(auto c : s){ if ('0' <= c && c <= '9'){ int num = c - '0'; if (num > first){ second = first; first = num; }elseif (num < first && num > second){ second = num; } } } return second; } // 使用有序集合set intsecondHighest(string s){ std::set<int> candidate; for(auto c : s){ if ('0' <= c && c <= '9'){ int num = c - '0'; candidate.emplace(num); } } return candidate.size() > 1 ? *prev(prev(candidate.end())) : -1; } };