Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions LongestSubstringWithMUniqueCharacters.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static String solution(String s, Integer m) throws Exception
}
end++;
//move start forward if number of unique characters is greater than m
while(!isLessThanM(hash,m))
while(!isLessThanM(hash,m)) // O(N) time in worst case when m = n.
{
int temp = hash.get((int)s.charAt(start));
hash.put((int)s.charAt(start),--temp);
Expand All @@ -73,7 +73,7 @@ public static String solution(String s, Integer m) throws Exception

}

public static boolean isLessThanM(HashMap<Integer,Integer> hash, Integer m)
public static boolean isLessThanM(HashMap<Integer,Integer> hash, Integer m) // O(HashMap size) runtime.
{
int count =0;
for(Integer key:hash.keySet())
Expand Down