384ms c# accepted solution


  • 0
    X
    public class Solution {
        public List<List<int>> Generate(int numRows) {
            var result = new List<List<int>>();
            var hash = new Dictionary<int, List<int>>();
            for (int i = 1; i <= numRows; ++i)
            {
                hash.Add(i, new List<int>());
                if (hash.ContainsKey(i - 1))
                {
                    for (int j = 1; j <= i; ++j)
                    {
                        if (j == 1 || j == i)
                        {
                            hash[i].Add(1);
                        }
                        else
                        {
                            hash[i].Add(hash[i - 1][j - 2] + hash[i - 1][j - 1]);
                        }
                    }
                }
                else
                {
                    hash[i].Add(1);
                }
            }
            for (int i = 1; i <= numRows; ++i)
                result.Add(hash[i]);
            return result;
        }
    }

Log in to reply
 

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