Search

์ด๊ฐ€ํ˜„

2.๋ฌธ์ œ์ด๋ฆ„
3. ์ˆ˜ํ–‰์‹œ๊ฐ„[์ดˆ(s)]
2580
์ข‹์•„์š” ๋ˆ„๋ฅด๊ธฐ
์ข‹์•„์š” ์ˆ˜
: 0
5 more properties
| ์ฝ”๋“œ ์ž‘์„ฑํ•˜๊ธฐ
public int[] solution(int[] answers) { int[] scores = {0, 0, 0}; //์ ์ˆ˜ int[] first = {1, 2, 3, 4, 5}; // 5๊ฐœ์”ฉ ๋ฐ˜๋ณต int[] second = {2, 1, 2, 3, 2, 4, 2, 5}; // 8๊ฐœ์”ฉ ๋ฐ˜๋ณต int[] third = {3, 3, 1, 1, 2, 2, 4, 4, 5, 5}; // 10๊ฐœ์”ฉ ๋ฐ˜๋ณต //๋งž์€ ๊ฐœ์ˆ˜ ๊ตฌํ•˜๊ธฐ for (int i = 0; i < answers.length; i++) { if (answers[i] == first[i % 5]) scores[0]++; if (answers[i] == second[i % 8]) scores[1]++; if (answers[i] == third[i % 10]) scores[2]++; } //๊ฐ€์žฅ ๋†’์€ ์ ์ˆ˜๋ฅผ ๋ฐ›์€์‚ฌ๋žŒ์ด ์—ฌ๋Ÿฌ๋ช…์ผ ๊ฒฝ์šฐ ์˜ค๋ฆ„์ฐจ์ˆœ //๊ฐ€์žฅ ๋†’์€ ์ ์ˆ˜๋ฅผ ๋ฐ›์€ ์‚ฌ๋žŒ int max = scores[0]; for (int i = 0; i < scores.length; i++) { if (max < scores[i]) max = scores[i]; } //list์— ์ˆ˜ํฌ์ž ๋ฒˆํ˜ธ๋„ฃ๊ธฐ List<Integer> list = new ArrayList<>(); //max๊ฐ€ ๊ฐ™์€์‚ฌ๋žŒ ์˜ค๋ฆ„์ฐจ์ˆœ for (int i = 0; i < scores.length; i++) { if (max == scores[i]) { list.add(i+1); } } //list๊ฐ’ ์ถœ๋ ฅ int[] answer = new int[list.size()]; for (int i = 0; i < list.size(); i++) { answer[i] = list.get(i); } return answer; }
Java
๋ณต์‚ฌ
| ์ฝ”๋“œ ์„ค๋ช…ํ•˜๊ธฐ
1.
์ˆ˜ํฌ์ž๊ฐ€ ๋งž์ถ˜ ๊ฐœ์ˆ˜๋ฅผ scores์— ๋‹ด๊ธฐ
2.
๊ฐ€์žฅ ๋†’์€ ์ ์ˆ˜๋ฅผ ๋งž์€ ์‚ฌ๋žŒ ๊ตฌํ•˜๊ธฐ
a.
์—ฌ๊ธฐ์„œ for๋ฌธ์„ ์‚ฌ์šฉํ–ˆ๋Š”๋ฐ ๋‹ค์Œ์—๋Š” Math.max ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๋” ์ค„์ผ์ˆ˜์žˆ์„๊บผ๊ฐ™๋‹ค
3.
๋ฐฐ์—ด์˜ ๊ธธ์ด์„ ๋งž์ถ˜ ์‚ฌ๋žŒ ์ˆ˜๋กœ ์กฐ์ ˆ์„ ์œ„ํ•ด์„œ list์— ๋‹ด๊ธฐ
4.
list ์ถœ๋ ฅ