We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8d9f017 commit d9c7181Copy full SHA for d9c7181
3011-find-if-array-can-be-sorted/3011-find-if-array-can-be-sorted.java
@@ -0,0 +1,21 @@
1
+class Solution {
2
+ public boolean canSortArray(int[] nums) {int n=nums.length;
3
+ for(int i=0;i<n;i++){
4
+ for(int j=i+1;j<n;j++){
5
+ if(nums[j]<nums[i]){
6
+ if(Integer.bitCount(nums[i])==
7
+ Integer.bitCount(nums[j])){
8
+ int temp=nums[i];
9
+ nums[i]=nums[j];
10
+ nums[j]=temp;
11
+ }
12
+ else return false;
13
14
15
16
+ for(int i=1;i<=n-1;i++){
17
+ if(nums[i]<nums[i-1]) return false;
18
19
+ return true;
20
21
+}
0 commit comments