Skip to content

Commit dfe654e

Browse files
committed
Time: 0 ms (100.00%) | Memory: 31.8 MB (33.78%) - LeetSync
1 parent 2eab6ea commit dfe654e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public:
3+
bool canSortArray(vector<int>& nums) {
4+
vector<pair<int,int>>v;
5+
v.push_back({nums[0],nums[0]});
6+
for(int i = 1 ; i < nums.size() ;i++)
7+
{
8+
int cur = __builtin_popcount(nums[i]);
9+
int prev = __builtin_popcount(nums[i-1]);
10+
if(cur != prev)
11+
{
12+
v.push_back({nums[i],nums[i]});
13+
}
14+
v.back().first = min(v.back().first,nums[i]);
15+
v.back().second = max(v.back().second,nums[i]);
16+
}
17+
for(int i = 1 ; i < v.size() ; i++)
18+
{
19+
if(v[i-1].second > v[i].first)
20+
return false;
21+
}
22+
return true;
23+
}
24+
};

0 commit comments

Comments
 (0)