8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b1b5865 commit 32d112aCopy full SHA for 32d112a
December 2024 Leetcode Solution/December-13.cpp
@@ -0,0 +1,26 @@
1
+class Solution {
2
+public:
3
+ long long findScore(vector<int>& nums) {
4
+ int n = nums.size();
5
+ vector<pair<int, int>> indexedNums;
6
+
7
+ for (int i = 0; i < n; i++) {
8
+ indexedNums.emplace_back(nums[i], i);
9
+ }
10
11
+ sort(indexedNums.begin(), indexedNums.end());
12
+ vector<bool> vis(n, false);
13
+ long long ans = 0;
14
15
+ for (auto& [val, idx] : indexedNums) {
16
+ if (!vis[idx]) {
17
+ ans += val;
18
+ vis[idx] = true;
19
+ if (idx > 0) vis[idx - 1] = true;
20
+ if (idx < n - 1) vis[idx + 1] = true;
21
22
23
24
+ return ans;
25
26
+};
0 commit comments