From 4385e6003e56f5a8e83b479cd55f0c5f4753c4c2 Mon Sep 17 00:00:00 2001 From: SinnoLn Date: Thu, 3 Dec 2026 22:55:19 +0900 Subject: [PATCH] 1711 --- .../1711. Count Good Meals.java" | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 "leetcode3/\354\235\264\354\247\204\355\235\254/1711. Count Good Meals.java" diff --git "a/leetcode3/\354\235\264\354\247\204\355\235\254/1711. Count Good Meals.java" "b/leetcode3/\354\235\264\354\247\204\355\235\254/1711. Count Good Meals.java" new file mode 100644 index 00000000..09ecac51 --- /dev/null +++ "b/leetcode3/\354\235\264\354\247\204\355\235\254/1711. Count Good Meals.java" @@ -0,0 +1,35 @@ + +/* +1. 아이디어: 해쉬맵 사용, 2의 거듭제곱은 최대 22번이므로 시간 안에 통과 가능 + +2. 시간복잡도: O(n*21) + +3. 자료구조/알고리즘: 해쉬맵 + +*/ +class Solution { + public int countPairs(int[] deliciousness) { + // 합의 차이가 정확히 2의 거듭제곱인 서로 다른 원소 + // 인덱스로 파악 + // 10^9 + 7 모듈러 연산 + + int MOD = 1000000007; + long ans = 0L; + + Map map = new HashMap<>(); + for(int i : deliciousness) { + int food = i; + int num = 1; + + for(int j=0; j<=21; j++) { + int tmp = num - food; + + if(map.containsKey(tmp)) ans = (ans+map.get(tmp))%MOD; + num*=2; + } + map.put(food, map.getOrDefault(food, 0)+1); + } + + return (int)ans; + } +} \ No newline at end of file