https://i.imgur.com/gsNoiha.png
https://i.imgur.com/ZRff8qC.png
Leetcode 744. Find Smallest Letter Greater Than Target
一样的code在 leetcode 上执行和在 VScode 执行上结果不同
自己trace过一遍觉得应该没问题
是有 bug 吗? 还是.....?
vector<char> letters = {'c' ,'f', 'j'};
char ans;
char target = 'k';
int left = 0;
int right = letters.size()-1;
while(left<=right){
int m = left+(right-left)/2;
if(letters[m]>target){
ans = letters[m];
right = m-1;
}
else if(letters[m]<=target)
left = m+1;
}
if(ans>target)
cout<<ans<<endl;
else
cout<<letters[0]<<endl;