Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1/20 HTTP + 전화번호목록 + 위장 #39

Open
skarltjr opened this issue Jan 20, 2021 · 1 comment
Open

1/20 HTTP + 전화번호목록 + 위장 #39

skarltjr opened this issue Jan 20, 2021 · 1 comment
Labels

Comments

@skarltjr
Copy link
Owner

package algo;


import java.util.Arrays;
import java.util.Comparator;

public class Solution {
    public boolean solution(String[] phone_book) {
        boolean answer = true;

        Arrays.sort(phone_book, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return Integer.compare(o1.length(), o2.length());
            }
        });
        //문자열 길이대로 정렬
        for (int i = 0; i < phone_book.length; i++) {
            for (int j = 0; j < phone_book.length; j++) {
                if (phone_book[j].startsWith(phone_book[i]) && i!=j) {
                    return false;
                }
            }
        }

        return answer;
    }
}


@skarltjr skarltjr changed the title 1/20 HTTP + 전화번호목록 1/20 HTTP + 전화번호목록 + 위장 Jan 20, 2021
@skarltjr
Copy link
Owner Author

package algo;


import java.util.HashSet;
import java.util.Set;

public class Solution {
    public int solution(String[][] clothes) {
        int answer = 1;
        Set<String> set = new HashSet<>();
        // 총 몇종류의 의상이 있는가 확인
        for (int i = 0; i < clothes.length; i++)
        {
            set.add(clothes[i][1]);
        }
        String[] kinds = new String[set.size()];
        int count = 0;
        for (String s : set)
        {
            kinds[count++] = s;
        }
        int[] kinds_count = new int[set.size()];

        //각각 clothes 돌면서 의상에 해당하는 index값 ++
        for (int i = 0; i < clothes.length; i++)
        {
            for (int j = 0; j < kinds.length; j++)
            {
                if (clothes[i][1].equals(kinds[j])) // String 은 레퍼런스타입 ==비교가아니다
                {
                    kinds_count[j]++;
                }
            }
        }

        for (int i = 0; i < kinds_count.length; i++) {
            answer *= (kinds_count[i] + 1);
        }


        return answer-1;
    }
}


@skarltjr skarltjr added the Daily label Jan 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant