diff --git a/3011. Find if Array Can Be Sorted b/3011. Find if Array Can Be Sorted new file mode 100644 index 0000000..5e97360 --- /dev/null +++ b/3011. Find if Array Can Be Sorted @@ -0,0 +1,17 @@ +class Solution { +public: + bool canSortArray(vector& nums) { + + vector 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; + } +};