class Solution {
public int longestContinuousSubstring(String s) {
int count=0;
for(int i=0;i<s.length();i++){
char ch = s.charAt(i);
int castascii = (int) ch;
int alpha=97;
if(castascii==alpha){
count++;
}
alpha++;
}
return count;
}
}
Example 1:
Input: s = "abacaba" // Only lower case
Output: 2
Explanation: There are 4 distinct continuous substrings: "a", "b", "c" and "ab". "ab" is the longest continuous substring.
Example 2:
Input: s = "abcde" // Only lower case
Output: 5
Explanation: "abcde" is the longest continuous substring.
My Code only Prints 1 Why is that?
I have used ASCII Values to solve can anyone help me.