We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Sherlock and the Valid String
Sherlock and the Valid String
Sort by
recency
|
2018 Discussions
|
Please Login in order to post a comment
time complexity: O(n):
if(len(s)>2): dic = {} for i in s: if(i in dic): dic[i]+=1 else: dic[i]=1
Can anyone tell me why test cases 7 & 13 are failing:
public static string isValid(string s) { if (s.Length == 1) return "YES"; Dictionary dict = new Dictionary(); foreach(char c in s){ if(!dict.ContainsKey(c)){ dict.Add(c, 1); }else{ dict[c]++; } }
I don't know if it is a right approach. Let me know guys if i can improve on this. Time Complexity:
O(N)
, whereN
is the length of the string. not adding other functions runtime 'cause they are just loop through constant size frequency table of size26
.Java8