免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
118 DIY LeetCode – Pascal’s Triangle (Java)
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, the result should be:
[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]Java Solution
public ArrayList<ArrayList<Integer>> generate(int numRows) { ArrayList<ArrayList<Integer>> result = new ArrayList<ArrayList<Integer>>(); if (numRows <= 0) return result;  ArrayList<Integer> pre = new ArrayList<Integer>(); pre.add(1); result.add(pre);  for (int i = 2; i <= numRows; i++) { ArrayList<Integer> cur = new ArrayList<Integer>();  cur.add(1); //first for (int j = 0; j < pre.size() - 1; j++) { cur.add(pre.get(j) + pre.get(j + 1)); //middle } cur.add(1);//last  result.add(cur); pre = cur; }  return result;}
自己寫(xiě)的
public class Solution { public List<List<int>> Generate(int numRows) { List<List<int>> ret=new List<List<int>>(); if(numRows==0) { return ret; } List<int> first=new List<int>(); first.Add(1); ret.Add(first); for(int i=2;i<=numRows;i++) { List<int> cur=new List<int>(); cur.Add(1); for(int j=0;j<first.Count-1;j++) { cur.Add(first[j]+first[j+1]); } cur.Add(1); ret.Add(cur); first=cur; } return ret; }}
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
47. 全排列 II
56. 合并區(qū)間
LeetCode——118. 楊輝三角
【小Y學(xué)算法】??每日LeetCode打卡??——33.楊輝三角
android平板上的GridView視圖緩存優(yōu)化
391,回溯算法求組合問(wèn)題
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服