Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int lengthOfLongestSubstring(String s) {
- Set<Character> set = new HashSet<>();
- char[] array = s.toCharArray();
- int max = 0;
- if(s.length() == 1) {
- return 1;
- }
- for(int i = 0; i<array.length; i++) {
- set = new HashSet<>();
- for(int j = i; j <array.length; j++) {
- if(!set.contains(array[j])) {
- // System.out.println(array[j]);
- set.add(array[j]);
- max = Math.max(set.size(), max);
- } else {
- break;
- }
- }
- }
- return max;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement