Product of Array Except Self
来源:互联网 发布:阿里云网站日志在哪里 编辑:程序博客网 时间:2024/05/21 11:34
int* productExceptSelf(int* nums, int numsSize, int* returnSize) { *returnSize=numsSize; int *output=(int*)malloc(sizeof(int)*numsSize); int i; output[0]=1; for(i=1;i<numsSize;i++){ output[i]=nums[i-1]*output[i-1]; } int temp=1; for(i=numsSize;i>=0;i++){ output[i]*=temp; temp*=nums[i]; } return output;}
第一遍先把这个数前面的加一遍
第二遍把这个数后面的书加一遍
只要计算2n次 就ok
0 0
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- Product of Array Except Self
- 递归函数时间复杂度分析
- MATLAB out of memory深层次解决办法
- 循环获取所有控件
- Candy
- UVA 348 Optimal Array Multiplication Sequence(最优矩阵链乘)
- Product of Array Except Self
- Qt 操作系统环境变量
- JVM垃圾回收
- 浅谈Android中的基础动画(图文详解)
- 背单词App开发日记6(终章总结)
- A1070. Mooncake (25)
- OC中继承代理委托类别
- Leetcode#114 Flatten Binary Tree to Linked List
- 随想