Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- array
- 코테
- bit manipulation
- 자바
- database
- SQL
- 파이썬
- Matrix
- string
- 코딩테스트
- geometry
- implement
- 구현
- simulation
- Data Structure
- dynamic programming
- Binary Search
- Method
- Number Theory
- Tree
- Math
- hash table
- Class
- Counting
- greedy
- two pointers
- Binary Tree
- Stack
- java
- sorting
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 118. Pascal's Triangle 본문
1. Input
1) int numRows
2. Output
1) numRows층으로 구성된 파스칼 삼각형을 리스트의 리스트로 반환
3. Constraint
1) 1 <= numRows <= 30
4. Example
Input: numRows = 5 -> Output: [[1],[1,1],[1,2,1],[1,3,3,1],[1,4,6,4,1]]
5. Code
1) 첫 코드(2023/05/12)
class Solution {
public List<List<Integer>> generate(int numRows) {
int[][] triangle = new int[numRows][numRows];
for(int[] a : triangle)
Arrays.fill(a, 1);
for(int i=2 ; i<triangle.length ; i++)
for(int j=1 ; j<i ; j++)
triangle[i][j] = triangle[i-1][j-1] + triangle[i-1][j];
List<List<Integer>> answer = new ArrayList<List<Integer>>();
for(int i=0 ; i<numRows ; i++){
List<Integer> list = new ArrayList<>();
for(int j=0 ; j<=i ; j++)
list.add(triangle[i][j]);
answer.add(list);
}
return answer;
}
}
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 144. Binary Tree Preorder Traversal (0) | 2023.05.12 |
---|---|
[LeetCode/Easy] 119. Pascal's Triangle II (0) | 2023.05.12 |
[백준 온라인 저지] 24416. 알고리즘 수업 - 피보나치 수 1 (0) | 2023.05.12 |
[백준 온라인 저지] 10798. 세로읽기 (0) | 2023.05.12 |
[백준 온라인 저지] 1316. 그룹 단어 체커 (0) | 2023.05.12 |