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.
2 parents 278634e + 9957009 commit 00c6b32Copy full SHA for 00c6b32
2460. Apply Operations to an Array
@@ -0,0 +1,25 @@
1
+class Solution {
2
+public:
3
+ vector<int> applyOperations(vector<int>& nums) {
4
+ int n= nums.size();
5
+ vector<int> v;
6
+ for (int i = 0; i < n - 1; i++) {
7
+ if (nums[i] == nums[i + 1]) {
8
+ nums[i] = nums[i]*2;
9
+ nums[i+1]=0;
10
+ }
11
12
+ for (int i = 0; i < n; i++) {
13
+ if (nums[i]!=0) {
14
+ v.push_back(nums[i]);
15
16
17
18
+ if (nums[i]==0) {
19
20
21
22
+ return v;
23
+
24
25
+};
0 commit comments