Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 429c352

Browse files
Update README and Dart solution comments to clarify prefix and suffix product concepts
1 parent cbc68aa commit 429c352

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
- Factorial
4747
- Hash Map Map (Hash Map ---- Linked Hash Map ---- Splay Tree Map)
4848
- 2 Pointers (Two Pointers) -> left and right pointers
49-
- Prefix sum
49+
- Prefix sum &&& Suffix sum
50+
- Prefic product &&& Suffix product
5051

5152

5253
### Algorithms

‎leetcode/238.product_of_array_except_self.dart

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// https://leetcode.com/problems/product-of-array-except-self/
2+
23
import 'package:test/test.dart';
34

45
void main() {
@@ -11,7 +12,8 @@ void main() {
1112
}
1213

1314
class Solution {
14-
////! Enhance Prefix Sum And Better Solution
15+
////! Enhance Prefix Product And Better Solution
16+
////! TC: O(2n) = O(n) --- SC: O(n)
1517
List<int> productExceptSelf(List<int> nums) {
1618
List<int> result = List.filled(nums.length, 1);
1719
int total = 1;
@@ -30,7 +32,27 @@ class Solution {
3032
return result;
3133
}
3234

33-
////! Under Standing using prefix sum
35+
////! Prefix Product From Udemy Video
36+
// List<int> productExceptSelf(List<int> nums) {
37+
// List<int> prefixProduct = List.filled(nums.length, 1);
38+
// prefixProduct[0] = 1;
39+
// int zerosCount = 0;
40+
// for (int i = 1; i < nums.length; i++) {
41+
// prefixProduct[i] = prefixProduct[i - 1] * nums[i - 1];
42+
// if (nums[i] == 0) zerosCount++;
43+
// if (zerosCount >= 2) return List.filled(nums.length, 0);
44+
// }
45+
// int suffixProductTotal = 1;
46+
47+
// for (int i = nums.length - 1; i >= 0; i--) {
48+
// prefixProduct[i] = prefixProduct[i] * suffixProductTotal;
49+
// suffixProductTotal *= nums[i];
50+
// }
51+
52+
// return prefixProduct;
53+
// }
54+
55+
////! Under Standing using prefix Product
3456
// List<int> productExceptSelf(List<int> nums) {
3557
// List<int> right = List.filled(nums.length, 1);
3658
// List<int> left = List.filled(nums.length, 1);
@@ -53,7 +75,8 @@ class Solution {
5375
// return result;
5476
// }
5577

56-
////! Accepted From the first time. TC: O(2n) = O(n)
78+
////! Accepted From the first time. TC: O(2n) = O(n) --- SC: O(n)
79+
////! Bad Solution With
5780
// List<int> productExceptSelf(List<int> nums) {
5881
// List<int> result = List.filled(nums.length, 0);
5982
// int total = 1;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /