A slow but Entirely Different Approach

• Consider the below logic in the picture.

``````import java.math.*;
public class Solution {
public String largestNumber(int[] nums) {
ArrayList<Integer> a = new ArrayList<Integer>();
for (int i = 0 ; i < nums.length; i++)
{
}
return largestNumber(a);
}
public String largestNumber(ArrayList<Integer> a)
{
int digits_in_max = Collections.max(a).toString().length();
ArrayList<shammy> sha = new ArrayList<shammy>();
for (int i = 0 ; i < a.size(); i++)
{
}
Collections.sort(sha, (p1, p2) -> (int)(p2.modifiedValue-p1.modifiedValue));
StringBuilder sb = new StringBuilder();
for (int i = 0; i < sha.size(); i++)
{
sb.append(new StringBuilder(Long.toString(sha.get(i).originalValue)));
}
BigInteger bi = new BigInteger(sb.toString());
return bi.toString();
}
}
class shammy
{
int originalValue;
long modifiedValue;
public shammy(int originalValue, int digits_in_max)
{
this.originalValue = originalValue;
String s = Integer.toString(originalValue);
StringBuilder sb = new StringBuilder(s);
StringBuilder ans = new StringBuilder();
while(ans.length() <= digits_in_max + 1)
{
ans.append(sb);
}
s = ans.toString().substring(0, digits_in_max + 1);
modifiedValue = Long.parseLong(s);
}
public String toString()
{
return "[" + modifiedValue + ", " + originalValue + "]";
}
}
``````

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