Skip to content

Looks inefficient to me. #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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