Skip to content

Commit c62e2f0

Browse files
authored
Create 3011. Find if Array Can Be Sorted
1 parent b106daf commit c62e2f0

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

3011. Find if Array Can Be Sorted

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
bool canSortArray(vector<int>& nums) {
4+
5+
vector<int> compareArray = nums;
6+
sort(compareArray.begin(), compareArray.end());
7+
8+
stable_sort(nums.begin(), nums.end(), [&](int a, int b) -> bool {
9+
if(__builtin_popcount(a) == __builtin_popcount(b)){
10+
return a < b;
11+
}
12+
return false;
13+
});
14+
15+
return compareArray == nums;
16+
}
17+
};

0 commit comments

Comments
 (0)