💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
Given an index k, return the kth row of the Pascal’s triangle. For example, given k = 3, Return [1,3,3,1]. ~~~ public class Solution { public List<Integer> getRow(int rowIndex) { List<Integer> list = new ArrayList<Integer>(); list.add(1); List<Integer> pre = new ArrayList<Integer>(list); for (int i = 1; i <= rowIndex; i++) { list.clear(); list.add(1); for (int j = 1; j < pre.size(); j++) { list.add(pre.get(j) + pre.get(j-1)); } list.add(1); pre.clear(); pre.addAll(list); } return list; } } ~~~