From 9957009d9114412e995cd0348bbd625d4df8a5f6 Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Sat, 1 Mar 2025 22:19:08 +0530 Subject: [PATCH] Create 2460. Apply Operations to an Array --- 2460. Apply Operations to an Array | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 2460. Apply Operations to an Array diff --git a/2460. Apply Operations to an Array b/2460. Apply Operations to an Array new file mode 100644 index 0000000..15f7066 --- /dev/null +++ b/2460. Apply Operations to an Array @@ -0,0 +1,25 @@ +class Solution { +public: + vector applyOperations(vector& nums) { + int n= nums.size(); + vector v; + for (int i = 0; i < n - 1; i++) { + if (nums[i] == nums[i + 1]) { + nums[i] = nums[i]*2; + nums[i+1]=0; + } + } + for (int i = 0; i < n; i++) { + if (nums[i]!=0) { + v.push_back(nums[i]); + } + } + for (int i = 0; i < n; i++) { + if (nums[i]==0) { + v.push_back(nums[i]); + } + } + return v; + + } +};