Skip to content

Commit 3558013

Browse files
committed
issue #27 IceCream Parlor java
1 parent 7c6bac4 commit 3558013

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package hackerrank;
2+
3+
import java.util.Arrays;
4+
5+
public class IceCreamParlor {
6+
static int[] icecreamParlor(int m, int[] arr) {
7+
// ์•„์ด์Šคํฌ๋ฆ„ ๋ง›์ข…๋ฅ˜ ๋ฐฐ์—ด์ธ arr์—์„œ ๊ฐ€์ง€๊ณ  ์žˆ๋Š” ๋ˆ m์œผ๋กœ ๋‘๊ฐ€์ง€ ๋ง›์„ ์‚ฌ๋ ค๋ฉด ๋ช‡๋ฒˆ์งธ ๋ง›์„ ๊ณจ๋ผ์•ผํ•˜๋Š” ์ง€๋ฅผ ๋ฆฌํ„ดํ•˜๋Š” ๋ฌธ์ œ์ด๋‹ค.
8+
int[] result = new int[2];
9+
10+
for (int i = 0; i < arr.length; i++) {
11+
for (int j = i + 1; j < arr.length; j++) {
12+
if (m == (arr[i] + arr[j])) {
13+
result[0] = i + 1;
14+
result[1] = j + 1;
15+
break;
16+
}
17+
}
18+
}
19+
20+
System.out.println(Arrays.toString(result));
21+
return result;
22+
}
23+
24+
public static void main(String[] args) {
25+
System.out.println(icecreamParlor(4, new int[] {1, 4, 5, 3, 2}) + ", ans: [1 4]");
26+
System.out.println(icecreamParlor(4, new int[] {2, 2, 4, 3}) + ", ans: [1 2]");
27+
}
28+
}

0 commit comments

Comments
ย (0)