class Solution { public: int totalSteps(vector<int>& nums) { int ans = 0;…
- User
class Solution { public: int totalSteps(vector& nums) { int ans = 0; stack<pair<int, int>> st; for (int num : nums) { int maxT = 0; while (!st.empty() && st.top().first <= num) { maxT = max(maxT, st.top().second); st.pop(); } maxT = st.empty() ? 0 : maxT + 1; ans = max(ans, maxT); st.emplace(num, maxT); } return ans; } };
int main() { int test[] = {5,3,4,4,7,3,6,11,8,5,11}; int test2[] = {20,1,9,1,2,3}; int test3[] = {9,1,2,3,4,1,5};
codeSolution s = Solution(); //如何测试 int ans = s.totalSteps(test);}
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.