# bigO time complexity of algorithm to find Longest Substring Without Repeating

public int lengthOfLongestSubstring(String s) {

//using a Collection to check if duplicate elements exist.

int count = 0;

int max = 0;

ArrayList

for(int i =0; i< s.length();i++){

String temp = Character.toString(s.charAt(i));

if(str.contains(temp)){

int idx = str.indexOf(temp);

for(int j = 0; j<= idx;j++) // clear all the elements before the duplicate elements, inluding the

str.remove(0); //duplicate. So, no elements collision in the new list.

str.add(temp);

count = str.size(); // update the count - the size of the new list.

}else {

str.add(temp);

count++;

if(count>max)

max=count;

}

}

return max;

}

Hi, what are time and space analysis? I think space complexity is O(n), but time complexity...

By: StackOverFlow - Thursday, 8 November

# Related Posts

- Older News
- How is BigO complexity equation calculated in general? StackOverFlow (Yesterday) - In worst case(failed to find sum ending up return false), what would be the complexity equation of the code and what's BigO of it?I put // and number of times...
- How to find the fitness of Sudoku in java StackOverFlow (3 days ago) - Suppose this is the matrix.I want fitness of this matrix for solving Sudoku. For example same number will repeated in column or row, in give example 2 in first row...
- String termination in java [duplicate] StackOverFlow (3 days ago) - This question already has an answer here:Why is “out of range” not thrown for 'substring(startIndex, endIndex)'6 answersString str="a"; System.out.print(str.substring(1));doubt:it shows no error but it should show out of bound because...