LeetCode:75. Sort Colors

来源:互联网 发布:长江证券mac版本 编辑:程序博客网 时间:2024/06/15 13:22

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.

这道题感觉自己用了一个sort的算法,然后就OK了。

AC:

class Solution {public:    void sortColors(vector<int>& nums) {        sort(nums.begin(),nums.end());    }};


0 0