zoukankan      html  css  js  c++  java
  • LeetCode 179 Largest Number 把数组排成最大的数

    Given a list of non negative integers, arrange them such that they form the largest number.
    For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.
    Note: The result may be very large, so you need to return a string instead of an integer.

     1 class Solution {
     2 public:
     3     string largestNumber(vector<int>& nums) {
     4         vector<string> arr;
     5         for(int n:nums)
     6             arr.push_back(to_string(n));
     7         sort(arr.begin(),arr.end(),[](string &str1,string &str2){return str1+str2>str2+str1;});
     8         string res;
     9         for(string s:arr)
    10             res+=s;
    11         if(res[0]=='0')
    12             return "0";
    13         return res;
    14     }
    15 };
  • 相关阅读:
    第五周作业
    关于结对编程的理解
    第四周作业
    总结
    总结
    总结
    总结
    总结
    判断树、判断表
    总结
  • 原文地址:https://www.cnblogs.com/xidian2014/p/8535946.html
Copyright © 2011-2022 走看看