C# clean solution using hashset


  • 0
    Y
    public class Solution {
        public IList<string> FindRepeatedDnaSequences(string s) {
            var res=new HashSet<string>();
            if(s.Length<11)
                return res.ToList();
            HashSet<string> stringDict=new HashSet<string>();
            for(int i=0;i<s.Length-9;i++)
            {
                string curString=s.Substring(i,10);
                if(!stringDict.Contains(curString))
                {
                    stringDict.Add(curString);
                    continue;
                }
                if(!res.Contains(curString))
                    res.Add(curString);
            }
            return res.ToList();
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.