# 179. Largest Number

Given a list of non negative integers, arrange them such that they form the largest number.

**Example 1:**

```
Input: [10,2]
Output: "210"
```

**Example 2:**

```
Input: [3,30,34,5,9]
Output: "9534330"
```

**Note:** The result may be very large, so you need to return a string instead of an integer.

```cpp
// Convert from int to string and sort
string largestNumber(vector<int>& nums) { // time: O(nlogn); space: O(n * str_len)
    sort(nums.begin(), nums.end(), [](const int& n1, const int& n2) {
        string s1 = to_string(n1), s2 = to_string(n2);
        return (s1 + s2) > (s2 + s1);
    });
    if (to_string(nums[0])[0] == '0') return "0";
    string res;
    for (const int& num : nums) {
        res += to_string(num);
    }
    return res;
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jimmylin1991.gitbook.io/practice-of-algorithm-problems/string/179.-largest-number.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
