Posts

Showing posts from September, 2021

Arithmetic Triangle

Image
Arithmetic Triangle Difficulty: Easy Given an integer  numRows , return the first numRows of Arithmetic 's triangle . In  Arithmetic's triangle , each number is the sum of the two numbers directly above it as shown: Solution:  Java class   Solution   {      List < List < Integer >>   list ;      public   List < List < Integer >>   generate ( int   numRows )   {          list = new   ArrayList <> ();          if ( numRows == 0 )              return   list ;          list . add ( new   ArrayList < Integer >( Arrays . asList ( 1 )));          for ( int   i = 1 ; i < numRows ; i ++){              List < Integer >   l = new   ArrayList < Integer >();              List < Integer >   prev = list . get ( i - 1 );              for ( int   j = 0 ; j <= i ; j ++){                  if ( i == 0 || j == 0 || i == 1 || i == j ){                      l . add ( 1 );                      continue ;                  }                  l