Skip to content

Commit ec3bd5f

Browse files
authored
Merge pull request #2073 from Ankush11903/patch-3
Create 1968-Array-With-Elements-Not-Equal-to-Average-of-Neighbors.cpp
2 parents c153bfe + 166d265 commit ec3bd5f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public:
3+
vector<int> rearrangeArray(vector<int>& nums) {
4+
vector<int> ans;
5+
for(int i=1;i<nums.size()-1;i++){
6+
int a=nums[i-1];
7+
int b=nums[i];
8+
int c=nums[i+1];
9+
if(a>b && b>c || a<b && b<c)
10+
{
11+
swap(nums[i],nums[i+1]);
12+
}
13+
}
14+
return nums;
15+
}
16+
};

0 commit comments

Comments
 (0)