Java、Python1051. Height Checker 高度检查器

it2022-05-05  218

题目


 

 

 

代码部分(Python 68ms 58.52%)

class Solution: def heightChecker(self, heights: List[int]) -> int: tmp = sorted(heights) return sum(tmp[i] != heights[i] for i in range(len(heights)))

 

 

 

 

代码部分(Java 2ms 99.21%)

class Solution { public int heightChecker(int[] heights) { int res = 0; int[] nums = new int[heights.length]; System.arraycopy(heights, 0, nums, 0, heights.length); Arrays.sort(nums); for(int i = 0; i < nums.length; i++){ if(nums[i] != heights[i]) res++; } return res; } }

 


最新回复(0)