From cd155a3f8e5e02bd537be420bf799158ef64d069 Mon Sep 17 00:00:00 2001 From: naryeong-ko Date: Sun, 5 Jun 2022 20:38:08 +0900 Subject: [PATCH 1/2] =?UTF-8?q?220605=5Fsolve=20:=20=EB=91=90=EA=B0=9C?= =?UTF-8?q?=EB=BD=91=EC=95=84=EC=84=9C=EB=8D=94=ED=95=98=EA=B8=B0=5Fko?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...353\215\224\355\225\230\352\270\260_ko.java" | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git "a/0614/Programmers/Lv1/\353\221\220\352\260\234\353\275\221\354\225\204\354\204\234\353\215\224\355\225\230\352\270\260_ko.java" "b/0614/Programmers/Lv1/\353\221\220\352\260\234\353\275\221\354\225\204\354\204\234\353\215\224\355\225\230\352\270\260_ko.java" index 8b13789..0e6337b 100644 --- "a/0614/Programmers/Lv1/\353\221\220\352\260\234\353\275\221\354\225\204\354\204\234\353\215\224\355\225\230\352\270\260_ko.java" +++ "b/0614/Programmers/Lv1/\353\221\220\352\260\234\353\275\221\354\225\204\354\204\234\353\215\224\355\225\230\352\270\260_ko.java" @@ -1 +1,18 @@ +class Solution { + public int[] solution(int[] numbers) { + int len = numbers.length; + int cnt = 0; + int[] sum = new int[201]; + for (int i = 0; i < len - 1; i++) + for (int j = i + 1; j < len; j++) + if (sum[numbers[i] + numbers[j]]++ == 0) + cnt++; // 중복 없는 개수 세기 + + int[] answer = new int[cnt]; + for (int i = 200; i > 0 && cnt >= 0; i--) + if (sum[i] > 0) + answer[--cnt] = i; + return answer; + } +} \ No newline at end of file From df3000df1a6006dabe21b2758fb45205d2ed8ed7 Mon Sep 17 00:00:00 2001 From: naryeong-ko Date: Sun, 5 Jun 2022 20:38:22 +0900 Subject: [PATCH 2/2] =?UTF-8?q?220605=5Fsolve=20:=20=EB=8B=A8=EC=B2=B4?= =?UTF-8?q?=EC=82=AC=EC=A7=84=EC=B0=8D=EA=B8=B0=5Fko?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\247\204\354\260\215\352\270\260_ko.java" | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git "a/0614/Programmers/Lv2/\353\213\250\354\262\264\354\202\254\354\247\204\354\260\215\352\270\260_ko.java" "b/0614/Programmers/Lv2/\353\213\250\354\262\264\354\202\254\354\247\204\354\260\215\352\270\260_ko.java" index 8b13789..876e7f0 100644 --- "a/0614/Programmers/Lv2/\353\213\250\354\262\264\354\202\254\354\247\204\354\260\215\352\270\260_ko.java" +++ "b/0614/Programmers/Lv2/\353\213\250\354\262\264\354\202\254\354\247\204\354\260\215\352\270\260_ko.java" @@ -1 +1,68 @@ +import java.util.HashMap; +class Solution { + static int answer; + static int[] place; + static HashMap map; + static int len; + + public int solution(int n, String[] data) { + answer = 0; + len = n; + place = new int[8]; + map = new HashMap<>(); // 카카오프렌즈 place 인덱스 + + map.put('A', 0); + map.put('C', 1); + map.put('F', 2); + map.put('J', 3); + map.put('M', 4); + map.put('N', 5); + map.put('R', 6); + map.put('T', 7); + + nPn(data, 0, 0); + + return answer; + } + + static void nPn(String[] data, int idx, int visit) { // 8명 순열 + if (idx == 8) { + if (check(data)) + answer++; + return; + } + + for (int i = 0; i < 8; i++) + if ((visit & (1 << i)) == 0) { // 이 위치 안 썼으면 + place[idx] = i; // idx는 카카오프렌즈, i는 이번 위치 + nPn(data, idx + 1, visit | (1 << i)); + } + } + + static boolean check(String[] data) { + int abDiff, diff; + for (int i = 0; i < len; i++) { + abDiff = Math.abs(place[map.get(data[i].charAt(0))] - place[map.get(data[i].charAt(2))]); + diff = data[i].charAt(4) - '0' + 1; + + switch (data[i].charAt(3)) { + case '=': + if (abDiff != diff) + return false; + break; + case '>': + if (abDiff <= diff) + return false; + break; + default: + if (abDiff >= diff) + return false; + break; + } + + } + return true; + } + +} \ No newline at end of file