[string sort] C++ 3ms lambda

  • 0
        string largestNumber(vector<int>& nums) {
            string res="";
            for(auto x:nums) vec.push_back(to_string(x));
            sort(vec.begin(),vec.end(),[](string& s1,string& s2){ return s1+s2>s2+s1; });
            for(auto x:vec) res+=x;
            int i=0;
            for(;i<res.size();i++) if(res[i]!='0') break;
            if(i==res.size()) res="0";
            return res;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.