Skip to content

Commit

Permalink
Merge pull request neetcode-gh#2073 from Ankush11903/patch-3
Browse files Browse the repository at this point in the history
Create 1968-Array-With-Elements-Not-Equal-to-Average-of-Neighbors.cpp
  • Loading branch information
MHamiid authored Jan 17, 2023
2 parents c153bfe + 166d265 commit ec3bd5f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cpp/1968-array-with-elements-not-equal-to-average-of-neighbors.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
public:
vector<int> rearrangeArray(vector<int>& nums) {
vector<int> ans;
for(int i=1;i<nums.size()-1;i++){
int a=nums[i-1];
int b=nums[i];
int c=nums[i+1];
if(a>b && b>c || a<b && b<c)
{
swap(nums[i],nums[i+1]);
}
}
return nums;
}
};

0 comments on commit ec3bd5f

Please sign in to comment.