기본 콘텐츠로 건너뛰기

프로그래머스 - 공항 건설하기

원래 dp로 풀었는데 알고보니, 단순 비교문제였음..
그냥 사람수가 가장 많은 도시는 고르면 되는 문제
import java.util.Arrays;

public class TryHelloWorld
{
    public int chooseCity(int n, int [][]city)
    {
        int idx=city[0][0];
        int max = city[0][1];
        for(int i=1;i<n;i++) {
            if(city[i][1]>max) {
                max = city[i][1];
                idx = city[i][0];
            }
        }

        return idx;
    }

    public static void main(String[] args)
    {
        TryHelloWorld test = new TryHelloWorld();
        int tn = 3;
        int [][]tcity = {{1,5},{2,2},{3,3}};
        System.out.println(test.chooseCity(tn,tcity));
    }

}

댓글

이 블로그의 인기 게시물

프로그래머스 - 시저 암호

public class Caesar { String caesar ( String s , int n ) { n %= 26 ; String result = "" ; char [] temp = s . toCharArray (); for ( int i = 0 ; i < temp . length ; i ++) { if ( temp [ i ]>= 'a' && temp [ i ]<= 'z' ) temp [ i ] = ( char ) (( temp [ i ]+ n )> 'z' ? ( temp [ i ]+ n - 1 )% 'z' + 'a' : ( temp [ i ]+ n )); else if ( temp [ i ]>= 'A' && temp [ i ]<= 'Z' ) temp [ i ] = ( char ) (( temp [ i ]+ n )> 'Z' ? ( temp [ i ]+ n - 1 )% 'Z' + 'A' : ( temp [ i ]+ n )); result += temp [ i ]; } return result ; } public static void main ( String [] args ) { Caesar c = new Caesar (); System . out . println ( "s는 'a B z', n은 4인 경우: " + c . caesar ( ...