Skip to content

Commit 299a222

Browse files
authored
Update number-of-unequal-triplets-in-array.cpp
1 parent 6a6ffec commit 299a222

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

C++/number-of-unequal-triplets-in-array.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ class Solution {
1010
unordered_map<int, int> cnt;
1111
vector<int> dp(K); // dp[i]: number of unequal (i+1)-plets
1212
for (const auto& x : nums) {
13+
++cnt[x];
1314
int other_cnt = 1;
1415
for (int i = 0; i < K; ++i) {
1516
dp[i] += other_cnt;
16-
other_cnt = dp[i] - (cnt[x] + 1) * other_cnt;
17+
other_cnt = dp[i] - cnt[x] * other_cnt;
1718
}
18-
++cnt[x];
1919
}
2020
return dp[K - 1];
2121
}

0 commit comments

Comments
 (0)