LeetCode OJ 系列之75 Sort Colors --Python
来源:互联网 发布:左耳最后说了什么 知乎 编辑:程序博客网 时间:2024/06/07 11:08
Problem:
Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.
Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.
Note:
You are not suppose to use the library's sort function for this problem.
class Solution(object): def sortColors(self, nums): """ :type nums: List[int] :rtype: void Do not return anything, modify nums in-place instead. """ num0 = 0 num1 = 0 num2 = 0 for i in nums: if i == 0 : num0+=1 if i == 1 : num1+=1 if i == 2 : num2+=1 for i in range(len(nums)): if i< num0: nums[i]=0 if i< num1+num0 and i>= num0: nums[i]=1 if i< num2+num1+num0 and i>= num1+num0: nums[i]=2
0 0
- LeetCode OJ 系列之75 Sort Colors --Python
- LeetCode OJ:Sort Colors
- LeetCode OJ - Sort Colors
- [LeetCode OJ]Sort Colors
- LeetCode OJ Sort Colors
- [python]leetcode(75). Sort Colors
- 【LeetCode】【Python】Sort Colors
- 【Leetcode】【python】Sort Colors
- 【LeetCode OJ 075】Sort Colors
- [LeetCode OJ]75. Sort Colors
- LeetCode之Sort Colors
- LeetCode之Sort Colors
- leetcode之Sort Colors
- LeetCode 之 Sort Colors
- 【Leetcode】之Sort Colors
- LeetCode OJ 之 Sort Colors(颜色排序)
- 【Leetcode长征系列】Sort Colors
- Leetcode 75 Sort Colors
- LeetCode OJ 系列之73 Set Matrix Zeroes --Python
- LeetCode OJ 系列之66 Plus One --Python
- 多图片平均法降噪
- LeetCode OJ 系列之65 Valid Number --Python
- LeetCode OJ 系列之58 Length of Last Word --Python
- LeetCode OJ 系列之75 Sort Colors --Python
- Medium题目总结
- LeetCode OJ 系列之165 Compare Version Numbers --Python
- LeetCode OJ 系列之151 Reverse Words in a String --Python
- eu in haskell
- Linux 学习路线图
- 回调函数透彻理解Java
- 【深夜】:为什么你是一个loser?
- Eclipse&JavaEE之中的引入项目运行错误问题