Skip to content

Latest commit

 

History

History
52 lines (39 loc) · 1.27 KB

_3. Longest Substring Without Repeating Characters.md

File metadata and controls

52 lines (39 loc) · 1.27 KB

All prompts are owned by LeetCode. To view the prompt, click the title link above.

Back to top


First completed : May 22, 2024

Last updated : July 01, 2024


Related Topics : Hash Table, String, Sliding Window

Acceptance Rate : 35.92 %


Solutions

Java

class Solution {
    public int lengthOfLongestSubstring(String s) {
        int maxSoFar = 0;
        for (int i = 0; i < s.length() && s.length() - i > maxSoFar; i++) {
            int counter = 0;
            HashSet<Character> temp = new HashSet<>();
            for (int j = i; j < s.length(); j++) {
                if (temp.contains(s.charAt(j))) {
                    break;
                } else {
                    temp.add(s.charAt(j));
                }

                counter++;
            }

            if (maxSoFar < counter) {
                maxSoFar = counter;
            }
        }

        return maxSoFar;
    }
}