[Leetcode]118 : Pascal’s Triangle

Link : https://leetcode.com/problems/pascals-triangle/

Problem :
Given an integer numRows, return the first numRows of Pascal's triangle.

圖來自leetcode
圖來自leetcode

Thoughts :
1. numRows是從1一開始。
2. 每一行的第一個跟最後一個數字都是1
3. 每一行的第 i 個值為 i-1 行第 j-1個加上 i-1 行第 j 個的值

Solution :

Time complexity = O(n²)(?, space complexity?

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store