-
[BaekJoon/Java] 1316. 그룹 단어 체커 - A0482022_PPS/3주차 2023. 1. 18. 19:26
- 문제

- 알고리즘
만약 같은 알파벳이 나오지 않고, alpha 라는 것에 true가 되어있으면 false로 한다.
그게 아니라면 true로 해서 result에 1을 더해준다.
- 코드
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); int result = 0; for(int i = 0; i<n; i++){ boolean cheak = true; boolean[] alpha = new boolean[26]; String str = s.next(); char ch = str.charAt(0); alpha[ch-97] = true; for(int j = 0; j<str.length(); j++){ if(str.charAt(j) != ch){ if(alpha[str.charAt(j)-97]){ cheak = false; break; } } alpha[str.charAt(j)-97] = true; ch = str.charAt(j); } if(cheak) result++; } System.out.println(result); } }'2022_PPS > 3주차' 카테고리의 다른 글
[LeetCode/Java] 228. Summary Ranges - A014 (0) 2023.01.18 [BaekJoon/Java] 2693. N번째 큰 수 - A081 (0) 2023.01.18 [LeetCode/Java] 728. Self Dividing Numbers - A037 (0) 2023.01.16 [LeetCode/Java] 367. Valid Perfect Square - A005 (0) 2023.01.16 [Programmers/Java] 스킬트리 - A005 (0) 2023.01.16