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
- 코딩테스트
- Counting
- Binary Tree
- simulation
- dynamic programming
- Stack
- bit manipulation
- array
- string
- Data Structure
- Math
- 구현
- database
- java
- two pointers
- Binary Search
- Method
- 자바
- sorting
- greedy
- 코테
- Class
- geometry
- SQL
- Number Theory
- hash table
- Tree
- implement
- 파이썬
- Matrix
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 125. Valid Palindrome 본문
1. Input
1) 문자열 변수 s
2. Output
1) palindrome이면 true, 아니면 false 반환
2) palindrome은 전부 소문자로 바꾸고 알파벳, 숫자를 제외한 모든 문자(공백 포함)를 없앴을 때, 앞에서 읽으나 뒤에서 읽으나 똑같다는 뜻
3. Constraint
1) 1 <= s.length <= 2 * 105
2) s는 ASCII 문자로만 이루어짐
4. Example
Input: s = "A man, a plan, a canal: Panama"
Output: true
설명:
- s의 문자열을 다 소문자로 바꾸고 알파벳을 뺀 나머지를 다 없애면 "amanaplanacanalpanama"이 된다.
- 앞에서부터 읽어도 뒤에서부터 읽어도 똑같으므로 true 반환
5. Code
1) 첫 코드(2022/08/12)
String ss = "";
for(int i=0 ; i<s.length() ; i++){
String c = s.charAt(i)+"";
if(c.matches("[A-Z]"))
ss += c.toLowerCase();
else if(c.matches("[a-z0-9]"))
ss += c;
}
for(int i=0 ; i<ss.length() ; i++)
if(ss.charAt(i)!=ss.charAt(ss.length()-1-i))
return false;
return true;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 171. Excel Sheet Column Number (0) | 2022.10.12 |
---|---|
[LeetCode/Easy] 136. Single Number (0) | 2022.10.11 |
[LeetCode/Easy] 88. Merge Sorted Array (0) | 2022.08.24 |
[LeetCode/Easy] 69. Sqrt(x) (0) | 2022.08.23 |
[LeetCode/Easy] 58. Length of Last Word (0) | 2022.08.23 |