a simple solution with lambda and sstream

  • 0

    simple and clear

            stringstream ss,ss1, ss2;
            sort(nums.begin(), nums.end(), [&](int l, int r) {
                ss1 << l << r;
                ss2 << r << l;
                return ss1.str() > ss2.str();
            for (int i : nums)
                ss << i;
            string temp = ss.str();
            if (temp[0] == '0') return std::to_string(0);
            return ss.str();

Log in to reply

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