Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- array
- Matrix
- two pointers
- simulation
- Stack
- Counting
- Tree
- string
- Method
- Number Theory
- implement
- bit manipulation
- 자바
- java
- database
- 코딩테스트
- Binary Search
- greedy
- 파이썬
- Binary Tree
- sorting
- Data Structure
- geometry
- 코테
- 구현
- Class
- dynamic programming
- Math
- hash table
- SQL
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 2299. Strong Password Checker II 본문
1. Input
1) String password
2. Output
1) password가 아래 조건을 만족한 강력한 비밀번호라면 true, 아니면 false 반환
// 비밀번호가 강력하기 위한 조건
- 길이는 최소 8이어야 한다.
- 영어 대문자는 최소 1개 있어야 한다.
- 영어 소문자는 최소 1개 있어야 한다.
- 숫자는 최소 1개 있어야 한다.
- 특수 문자는 최소 1개 있어야 한다. 사용할 수 있는 특수 문자는 !@#$%^&*()-+ 뿐이다.
- 같은 문자가 2개 붙어 있으면 안 된다.
3. Constraint
1) 1 <= password.length <= 100
2) password에는 조건에 언급된 문자 외에 다른 것은 없다.
4. Example
Input: password = "IloveLe3tcode!" -> Output: true
Input: password = "Me+You--IsMyDream" -> Output: false
설명:
- 모든 조건을 만족하기 때문에 true
- 숫자가 없고, 같은 문자가 2개 붙어있기 때문에(--) false
5. Code
1) 첫 코드(2022/06/27)
if(password.length() < 8)
return false;
int[] count = {0,0,0,0};
for(int i=0 ; i<password.length() ; i++){
char c = password.charAt(i);
if(65 <= c && c <= 90) // upper
count[0]++;
else if(97 <= c && c <= 122) // lower
count[1]++;
else if(48 <= c && c <= 57) // digit
count[2]++;
else if((c+"").matches("[!@#$%^&*\\(\\)\\-+]")) // special
count[3]++;
else
return false;
}
for(int i=0 ; i<=3 ; i++)
if(count[i]==0)
return false;
for(int i=0 ; i<password.length()-1 ; i++)
if(password.charAt(i) == password.charAt(i+1))
return false;
return true;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 2319. Check if Matrix Is X-Matrix (0) | 2023.01.16 |
---|---|
[LeetCode/Easy] 2315. Count Asterisks (0) | 2023.01.16 |
[LeetCode/Easy] 2283. Check if Number Has Equal Digit Count and Digit Value (0) | 2023.01.16 |
[LeetCode/Easy] 2278. Percentage of Letter in String (0) | 2023.01.16 |
[LeetCode/Easy] 2269. Find the K-Beauty of a Number (0) | 2023.01.16 |