Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Bug Report for longest-substring-without-duplicates #4886

Open
@anshul-rohilla4

Description

@anshul-rohilla4

Bug Report forhttps://neetcode.io/problems/longest-substring-without-duplicates

Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.

in the problem , we are asked to get the length of a substring with no no repeating chars.
index starting form 1 for the length;
whereas in the third test case pwwkew, the solution should be 2 casue the third element 'w' is being repeated but the provided expected outcomes is given to be 3.

public int lengthOfLongestSubstring(String s) {
HashMap<Character,Integer> hash=new HashMap<>();
int index=0;
for( char ch:s.toCharArray()){
if(hash.containsKey(ch))return index;
else hash.put(ch,1);
index++;
}
return index-1;
}

the above is the copy of my solution.

If I’m mistaken, I’d appreciate it if you could point out where I went wrong so I can correct my understanding.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp