C# solution with Dictionary

  • 2
    public class Solution {
        public IList<IList<string>> FindDuplicate(string[] paths) {
            var dict = new Dictionary<string, IList<string>>();
            foreach(var dfs in paths){
                var df = dfs.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries);
                if(df.Length<=1) continue;
                var dir = df[0];
                for(var i=1;i<df.Length;++i){
                    var f = df[i];
                    var index = f.IndexOf('('); //e.g.  "a(1)"; index = 1;
                    var filename = f.Substring(0, index);
                    var content = f.Substring(index+1, f.Length-1 - index-1);
                    if(!dict.ContainsKey(content)) dict[content] = new List<string>();
                    var fullname = dir+"/"+filename;
            IList<IList<string>> res = new List<IList<string>>();
            foreach(var kv in dict){
            return res;

  • 0

    Any clue why this would give run time error?

      return (IList<IList<string>>) dict.Values.ToList();

Log in to reply

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