• 21.8%

https://leetcode.com/problems/largest-number/?tab=Description

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

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

https://discuss.leetcode.com/topic/7286/a-simple-c-solution

A simple C++ solution

string此处用的begin(arr),不同于vector的arr.begin()

erase(0, 1) erase(start, end), 其中删除关系[start, end)

erase 的用法

iterator erase (iterator position);

iterator erase (iterator first, iterator last);

position

Iterator pointing to a single element to be removed from the vector.

Member types iterator and const_iterator are random access iterator types that point to elements.

first, last

Iterators specifying a range within the vector] to be removed: [first,last). i.e., the range includes all the elements between first and last, including the element pointed by first but not the one pointed by last.

Member types iterator and const_iterator are random access iterator types that point to elements.

#### 剑指offer 33

string可以相加 a+b

https://discuss.leetcode.com/topic/10920/share-a-short-code-in-c

Share a short code in c++

https://discuss.leetcode.com/topic/12293/simple-10-line-c-solution

Simple 10-line C++ Solution

https://discuss.leetcode.com/topic/7722/python-simple-solution-in-4-lines

Python simple solution in 4 lines

It’s all about comparison . We define a func that compares two strings a ,b. we consider a bigger than b if a+b > b+a . then we sort the numbers and concatenate them .

UPDATE

More explanation

1-we define a function that compares two string (a,b) . we consider a bigger than b if a+b>b+a
for example : (a=”2”,b=”11”) a is bigger than b because “211” >”112”

2-convert all elements of the list from int to string

3-sort the list descendingly using the comparing function we defined
for example sorting this list [“2”,”11”,”13”] using the function defined in step 1 would produce [“2”,”13”,”11”]

4-we concatatenate the list “21311”

https://discuss.leetcode.com/topic/7235/my-3-lines-code-in-java-and-python

My 3-lines code in Java and Python

The logic is pretty straightforward. Just compare number by convert it to string.

Thanks for Java 8, it makes code beautiful.

Java:

Python:

class Solution:

https://discuss.leetcode.com/topic/32442/share-my-fast-java-solution-beat-98-64

Share my fast JAVA solution, beat 98.64%!

https://discuss.leetcode.com/topic/8018/my-java-solution-to-share

My Java Solution to share

The idea here is basically implement a String comparator to decide which String should come first during concatenation. Because when you have 2 numbers (let’s convert them into String), you’ll face only 2 cases:

Apparently, case1 is greater than case2 in terms of value.
So, we should always put s1 in front of s2.

I have received many good suggestions from you in this discussion. Below is the modified version of codes based on your suggestions:

In terms of Time and Space Complexity:
Let’s assume:
the length of input array is n,
average length of Strings in s_num is k,
Then, compare 2 strings will take O(k).
Sorting will take O(nlgn)
Appending to StringBuilder takes O(n).
So total will be O(nklgnk) + O(n) = O(nklgnk).

Space is pretty straight forward: O(n).