if I change s = 0 and l = n-1. then why not work? LEETCODE–374. Guess Number Higher or Lower
public class Solution extends { THIS IS CLASS
public ( n) {TAKING A NO. N
s = 1;S IS START
l = IS LAST m = 0 m = s + (l-s)/2;
M IS MIDDLE while(s<=l)
WHILE LOOP`
{
m = s + (l-s)/2;`MIDDLE`
g = guess(m);`G IS GIVING 0,1,-1 `
if(g==0)
break;
else if(g==-1)
l = m-1;
else
s = m + 1;
}return m;
}
}
I assign s=0 and l =n-1, then why not work. I know its very basic but I am some how confused.
New contributor
Shashwat is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.