728x90
SMALL

using System;
using System.Collections.Generic;

public class Solution {
    public string solution(int[] numbers) {
        List<string> lstnumber=new List<string>();
        List<string> builder = new List<string>();
        
        for(int i=0; i<numbers.Length; i++)
        {
            lstnumber.Add(numbers[i].ToString());
        }
        lstnumber.Sort((a,b)=>(b+a).CompareTo(a+b));
        
        foreach(var str in lstnumber)
        {
            builder.Add(str);
        }
        
        string answer = string.Join("",builder);
        if(answer[0]=='0') return "0";
        return answer;
    }
}

 

////

 

 

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

public class Solution {
    public string solution(int[] numbers)
    {
        Array.Sort(numbers, (x, y) =>
        {
            string XY = x.ToString() + y.ToString();
            string YX = y.ToString() + x.ToString();
            return YX.CompareTo(XY);
        });
        if (numbers.Where(x => x == 0).Count() == numbers.Length) return "0";
        else return string.Join("", numbers);
    }
}
728x90

설정

트랙백

댓글