Hello all,
I am trying to solve a coding problem in Java that involves finding the longest substring without repeating characters. I have written a program to do so, but I'm having trouble debugging it and getting it to run correctly.
Here's the code I have written so far:
public static int lengthOfLongestSubstring(String s) {
int max = 0;
HashMap<Character, Integer> map = new HashMap<>();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (map.containsKey(c)) {
max = Math.max(max, i - map.get(c));
}
map.put(c, i);
}
return max;
}
I am getting the following error message when I try to compile the code:
Error: cannot find symbol
I would really appreciate any help in resolving this issue.
Thanks in advance!