LeetCode Username
jayesh2211
Problem Number, Title, and Link
- Find Smallest Letter Greater Than Target
Bug Category
Problem examples
Bug Description
Best logical code for find smallest letter gretaer than target leetcode problem no.744
Language Used for Code
Java
Code used for Submit/Run operation
class Solution {
public char nextGreatestLetter(char[] letters, char target) {
int low=0;
int high=letters.length-1;
char ans=letters[0];
while(low<=high){
int mid=(low+high)/2;
if(letters[mid]<=target){
low=mid+1;
}
else{
ans=letters[mid];
high=mid-1;
}
}
return ans;
}
}
Expected behavior
.
Screenshots
Additional context
No response