There was an error while loading. Please reload this page.
2 parents d7bb5f6 + b8e6f9f commit 6d53e7dCopy full SHA for 6d53e7d
1 file changed
leetcode3/염혜정/3803. Count Residue Prefixes.java
@@ -0,0 +1,21 @@
1
+// 문자열의 0번째부터 set에 있는지 확인
2
+// 없으면 넣어주고 distinct_cnt + 1
3
+// O(n)
4
+
5
+class Solution {
6
+ public int residuePrefixes(String s) {
7
+ Set<Character> set = new HashSet<>();
8
+ int distinct_cnt = 0;
9
+ int result = 0;
10
+ for (int i = 0; i<s.length(); i++) {
11
+ char c = s.charAt(i);
12
+ if (!set.contains(c)) { // 중복이 아니라면
13
+ distinct_cnt++;
14
+ set.add(c);
15
+ }
16
+ int modulo = (i + 1) % 3;
17
+ if (modulo == distinct_cnt) result++;
18
19
+ return result;
20
21
+}
0 commit comments