MapleStory Finger Point

๐Ÿƒ‍โ™€๏ธprogrammers/Java

ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค - java ๋ฌธ์ž์—ด ์ž˜๋ผ์„œ ์ •๋ ฌํ•˜๊ธฐ

HYEJU01 2024. 5. 8. 09:27

๐Ÿ’ก ์‚ฌ์ „์ˆœ์ด๋ฉด ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌํ•ด์ฃผ๋ฉด ๋œ๋‹ค. ์ด๋•Œ ๊ณต๋ฐฑ๊ฐ’์€ ์ œ์™ธํ•ด์•ผํ•œ๋‹ค๋Š” ์ !!

 

 

 ๐Ÿ’ฌ Arrays.sort() :: ๋ฐฐ์—ด์˜ ์š”์†Œ๋ฅผ ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ ์ •๋ ฌ

import java.util.Arrays;
import java.util.ArrayList;

class Solution {
    public ArrayList<String> solution(String myString) {
         String[] answer = myString.split("x"); // x ๊ธฐ์ค€์œผ๋กœ ์ž๋ฅด๊ธฐ
        ArrayList<String> str = new ArrayList<>();
        
        Arrays.sort(answer); // ์ •๋ ฌ
        
        for (String s : answer){ // ๋น„์–ด์žˆ์ง€ ์•Š์€ ๊ฒƒ๋งŒ ์ƒˆ๋กœ์šด ๋ฐฐ์—ด๋กœ ๋„ฃ๊ธฐ 
            if (!s.isEmpty()){
                str.add(s);
            }
        }
        
        return str;
    }
}