leetcode:Product of Array Except Self
来源:互联网 发布:西门子840dsl编程手册 编辑:程序博客网 时间:2024/06/07 22:38
这道题目我记得是某一年腾讯的笔试题目来的,
给出一个数组,求出除了对应位置数字外的数组乘积
public class Solution { public int[] productExceptSelf(int[] nums) { if(nums == null || nums.length == 0){ return null; } int[] output = new int[nums.length]; Arrays.fill(output, 1); int temp = 1; output[0] = temp; for(int i = 1, len = nums.length - 1; i <= len; ++i){ temp *= nums[i - 1]; output[i] = temp; } temp = 1; for(int i = nums.length - 2; i >= 0; --i){ temp *= nums[i + 1]; output[i] *= temp; } return output; }}
0 0
- [leetcode][array] Product of Array Except Self
- 【LeetCode】237 Product of Array Except Self
- #leetcode#Product of Array Except Self
- leetcode 238: Product of Array Except Self
- [leetcode] 238.Product of Array Except Self
- [leetcode] Product of Array Except Self
- LeetCode Product of Array Except Self
- leetCode(43):Product of Array Except Self
- LeetCode Product of Array Except Self
- 【leetcode】Product of Array Except Self
- 【leetcode】Product of Array Except Self
- leetcode: Product of Array Except Self
- [leetcode] Product of Array Except Self
- [LeetCode] Product of Array Except Self
- Leetcode: Product of Array Except Self
- LeetCode 238: Product of Array Except Self
- LeetCode-Product of Array Except Self
- Leetcode #238 Product of Array Except Self
- spring中scope作用域(转)
- 诸葛孔明的简洁之美
- LCA 转 RMQ算法 【总结】
- 原来新建一个类,需要那么长的代码,瞬间觉得有点疲惫了 ~
- hdu-2037/akoj-1251-今年暑假不AC(C#结构体排序)
- leetcode:Product of Array Except Self
- 一步一步学Android
- HDU 3746 Cyclic Nacklace 利用 KMP的next数组求循环节
- linux系统的颜色配置
- http协议学习和总结系列
- canvas的基本使用
- JAVA基础篇八(Java,C++中的网络)
- wget cookies 欺骗
- Netty官方指南: User guide for 4.x