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 e88d463 commit b6fb231Copy full SHA for b6fb231
TwoPointers/2460.apply-operations-to-an-array.cpp
@@ -0,0 +1,32 @@
1
+/*
2
+ * @lc app=leetcode id=2460 lang=cpp
3
+ *
4
+ * [2460] Apply Operations to an Array
5
+ */
6
+
7
+// @lc code=start
8
+#include "bits/stdc++.h"
9
+using namespace std;
10
11
+class Solution {
12
+public:
13
+ vector<int> applyOperations(vector<int>& nums) {
14
+ int size = nums.size();
15
+ for(int i=0;i<size-1;i++){
16
+ if(nums[i] && nums[i]==nums[i+1]){
17
+ nums[i]*=2;
18
+ nums[i+1]=0;
19
+ }
20
21
+ int pos = 0;
22
+ for(int i = 0; i < size; i++) {
23
+ if (nums[i] != 0) {
24
+ swap(nums[i], nums[pos]);
25
+ pos++;
26
27
28
+ return nums;
29
30
+};
31
+// @lc code=end
32
0 commit comments