C# List beat 96.39%


  • 0
    public class Solution {
        public IList<string> LetterCombinations(string digits) {
            IList<string> rs=new List<string>();
            if(!string.IsNullOrEmpty(digits))
            {
                string[] dics={"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};
                rs.Add("");
                for(int i=0;i<digits.Length;i++)
                {
                    foreach(string item in rs.Where(m=>m.Length==i).ToList())
                    {
                        foreach(char c in dics[Convert.ToInt32(digits[i].ToString())])
                        {
                            rs.Add(item+c.ToString());
                        }
                    }
                    rs=rs.Where(m=>m.Length==i+1).ToList();
                }
            }
            return rs;
            
        }
    }

Log in to reply
 

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