Skip to content

Commit a771fb3

Browse files
committed
Prob:165 product except self, updated solution with comments
1 parent 57efc15 commit a771fb3

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
| Current Status| Stats |
88
| :------------: | :----------: |
9-
| Total Problems | 164 |
9+
| Total Problems | 165 |
1010

1111
</center>
1212

leet_code_problems/product_except_self.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@
99
#include <iostream>
1010
#include <vector>
1111

12+
13+
/*
14+
* Idea is to maintain two product variables, one from beginning and
15+
* one from the end.
16+
* Each result variable in result array
17+
* would be touched twice, one from the left to right
18+
* and other right to left, thus producing desired result.
19+
*/
1220
std::vector<int> product_except_self(const std::vector<int>& nums)
1321
{
1422
int product_from_beginning = 1;

0 commit comments

Comments
 (0)