题目:
方法:
python可以用一种偷懒的方法
使用python内置的sort()排序
直接一行代码搞定
class Solution(object): def sortColors(self, nums): """ :type nums: List[int] :rtype: void Do not return anything, modify nums in-place instead. """ nums.sort()
我们再用传统的冒泡排序完成一遍
class Solution(object): def sortColors(self, nums): """ :type nums: List[int] :rtype: void Do not return anything, modify nums in-place instead. """ for i in range(len(nums)-1): for j in range(i+1,len(nums)): if nums[i] > nums[j] : temp = nums[i] nums[i] = nums[j] nums[j] = temp很简单的一道题,考察排序的方法。