My Python solution by concat half result and its reverse


  • 0
    R
    class Solution:
    
        def getRow(self, rowIndex):
            """
            :type rowIndex: int
            :rtype: List[int]
            """
            if rowIndex <= 1:
                return [1] * (rowIndex + 1)
            
            result = [1, 1]
            for n in range(2, rowIndex + 1):
                end_idx1 = int(n / 2)
                end_idx2 = int((n + 1) / 2)
                for i in range(end_idx1, 0, -1):
                    result[i] += result[i - 1]
                    
                result = result[:end_idx1 + 1] + result[:end_idx2][::-1]
            
            return result
    

Log in to reply
 

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