Skip to content

Commit

Permalink
Create 3011. Find if Array Can Be Sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Nov 6, 2024
1 parent b106daf commit c62e2f0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions 3011. Find if Array Can Be Sorted
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
public:
bool canSortArray(vector<int>& nums) {

vector<int> compareArray = nums;
sort(compareArray.begin(), compareArray.end());

stable_sort(nums.begin(), nums.end(), [&](int a, int b) -> bool {
if(__builtin_popcount(a) == __builtin_popcount(b)){
return a < b;
}
return false;
});

return compareArray == nums;
}
};

0 comments on commit c62e2f0

Please sign in to comment.