jayati

Largest Number formed from an Array

Aug 12th, 2023
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.54 KB | None | 0 0
  1. class Solution{
  2. public:
  3.     // The main function that returns the arrangement with the largest value as
  4.     // string.
  5.     // The function accepts a vector of strings
  6.     static bool compareStrings(const string &a, const string &b) {
  7.     return a + b > b + a;
  8. }
  9.     string printLargest(vector<string> &arr) {
  10.      sort(arr.begin(), arr.end(), compareStrings);
  11.  
  12.     string result = "";
  13.     for (const string &s : arr) {
  14.         result += s;
  15.     }
  16.  
  17.     return result;
  18.     }
  19. };
  20. https://practice.geeksforgeeks.org/problems/largest-number-formed-from-an-array1117/
Advertisement
Add Comment
Please, Sign In to add comment