题解 | #把数组排成最小的数#

把数组排成最小的数

https://www.nowcoder.com/practice/8fecd3f8ba334add803bf2a06af1b993?tpId=265&rp=1&ru=%2Fexam%2Foj%2Fta&qru=%2Fexam%2Foj%2Fta&sourceUrl=%2Fexam%2Foj%2Fta%3FjudgeStatus%3D3%26page%3D1%26pageSize%3D50%26search%3D%26tpId%3D13%26type%3D265&difficulty=&judgeStatus=3&tags=&title=&gioEnter=menu

利用了STL,思路易懂,但是如果舍弃STL实现有点难度

class Solution {
  public:
    string PrintMinNumber(vector<int> numbers) {
      std::string res;
      if (numbers.empty()) {
        return res;
      }
      
      std::sort(numbers.begin(), numbers.end(), [](int a, int b) -> bool {return std::to_string(a) + std::to_string(b) < std::to_string(b) + std::to_string(a);});
      
      for (int i = 0; i < numbers.size(); ++i) {
        res += std::to_string(numbers[i]);
      }
      
      return res;
    }
};
全部评论

相关推荐

rbjjj:太杂了吧,同学,项目似乎都没深度,都是api调度耶,分层架构思想没有体现出来了,前端没有前端优化前端工程化体现,后端微服务以及分层架构没体现以及数据安全也没体现,核心再改改,注重于计算机网络,工程化,底层原理吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务