Skip to content

Longest Substring Without Repeating Characters #32432

@vishwa-0315

Description

@vishwa-0315

LeetCode Username

vishwa_7

Problem Number, Title, and Link

Longest Substring Without Repeating Characters,https://leetcode.com/problems/longest-substring-without-repeating-characters/submissions/1780963433

Bug Category

Problem constraints

Bug Description

Longest Substring Without Repeating Characters

Language Used for Code

Java

Code used for Submit/Run operation

class Solution {
    public int lengthOfLongestSubstring(String s) {
        int n = s.length();
        int[] freq = new int[128];
        int left = 0, right = 0, maxLen = 0;
        while (right < n) {
            char c = s.charAt(right);
            freq[c]++;
            while (freq[c] > 1) {
                char d = s.charAt(left);
                freq[d]--;
                left++;
            }
            maxLen = Math.max(maxLen, right - left + 1);
            right++;
        }
        return maxLen;
    }
}

Expected behavior

Longest Substring Without Repeating Characters
it will not repeat the substring

Screenshots

No response

Additional context

No response

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions