Algorithm/기타

1. 로또의 최고 순위와 최저 순위 이중 for문 풀이 class Solution { public int[] solution(int[] lottos, int[] win_nums) { int count = 0; int zero = 0; for (int l : lottos) { for (int w : win_nums) { if (l == w) count++; } if (l == 0) zero++; } int bottomRank = count == 0 ? 6 : 7 - count; int topRank = count + zero == 0 ? 6 : 7 - (count + zero); return new int[] {topRank, bottomRank}; } } Map 풀이 import java.util.Has..
for 문 X보다 작은 수 import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int x = sc.nextInt(); ArrayList arr = new ArrayList(); for (int i = 0; i < n; i++) { int m = sc.nextInt(); if (m < x) { arr.add(m); } } for (Integer integer : arr) { System.out.print(integer + " "); } } } arra..
코너.
'Algorithm/기타' 카테고리의 글 목록 (2 Page)