C# solution beats 100% and easy to understand


  • 0
    T
        public IList<int> GetRow(int rowIndex) {
                IList<int> res = new List<int> { 1 };
                if (rowIndex == 0)
                    return res;
                res.Add(1);
                if (rowIndex == 1)
                    return res;
                int temp1 = 1,temp2;
                for (int i = 1; i < rowIndex; i++)
                {
                    for (int j = 1; j < i + 1; j++)
                    {
                        temp2 = res[j];
                        res[j] = res[j] + temp1;
                        temp1 = temp2;
                    }
                    res.Add(1);
                }
                return res;
        }
    

Log in to reply
 

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