LeetCode 744. Find Smallest Letter Greater Than Target (时间复杂度O(n))

题目

LeetCode 744. Find Smallest Letter Greater Than Target (时间复杂度O(n))

太简单了,直接上代码:

class Solution {
public:
char nextGreatestLetter(vector<char>& letters, char target) {
int n = letters.size();
int a[] = {};
for(int i = ;i < n; ++i){
a[letters[i]-'a']++;
}
for(int i = (target-'a'+)%; ; i++,i%=){
if(a[i] > ) return (char)(i + 'a');
}
}
};
上一篇:744. Find Smallest Letter Greater Than Target


下一篇:[LeetCode&Python] Problem 744. Find Smallest Letter Greater Than Target