Java Code Problem: Longest Substring Without Repeating Characters

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!

@Alishh , hi,

You need a 'main' method in order to produce an executable.

find an online resource showing you how to write and build basic java programs.

confirm platform (ubuntu/mint/...) and java versions being used.

NB: I've not attempted to analyse or debug your code , so any other issues are as yet to be discussed.

(Just have seen the link...)

This topic was automatically closed 300 days after the last reply. New replies are no longer allowed.