题目链接 点击打开链接
这个 题目我确实不知道怎么用最低的内存使用量解决。而是看了别人的方法。这个方法确实比较妙。
public class Solution {
public List<Integer> getRow(int rowIndex) {
Integer tempArr[]=new Integer[rowIndex+1];
for(int i=0;i<rowIndex+1;i++)
{
tempArr[i]=0;
}
tempArr[0]=1;
for(int i=1;i<=rowIndex;i++)
{
for(int j=i;j>=1;j--)
{
tempArr[j]=tempArr[j]+tempArr[j-1];
}
}
return Arrays.asList(tempArr);
}
}
这个是运行时间。可以看到语言的不同速度。c还是最快的。其次是cpp。然后是python(都说Python慢,其实真的不是。可能我的运行时间里面包括了jvm的启动时间)。c#是真慢啊!