>> 문제설명
leetcode.com/problems/remove-palindromic-subsequences/
Remove Palindromic Subsequences - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
1. 문제를 잘 읽어야 함.
2. 영어실력을 기르자.
문제에서 주어진 문자열의 일부를 순서를 바꾸지 않은 상태로 지워 subsequence를 만들 수 있다고 했다.
이것을 어떻게 이해한것인지 문자열을 끊어서 일부만 지워 subsequence를 만들 생각을 못했다.
이것을 이해했다면 아주 간단한것인데..
> Solution
class Solution {
boolean isPal(String str){
for(int idx = 0; idx < str.length()/2; idx++){
if(str.charAt(idx) != str.charAt(str.length()-idx-1)) return false;
}
return true;
}
public int removePalindromeSub(String s) {
if(s.length() == 0){
return 0;
}
if(isPal(s)){
return 1;
}
return 2;
}
}
728x90
반응형
'Algorithms > LeetCode DailyChallenge' 카테고리의 다른 글
| [LeetCode] 1721. Swapping Nodes in a Linked List / JAVA (0) | 2021.03.14 |
|---|---|
| [LeetCode] 322. Coin Change / JAVA (0) | 2021.03.12 |
| [LeetCode] 12. Integer to Roman / JAVA (0) | 2021.03.10 |
| [LeetCode] Short Encoding of Words (0) | 2021.03.06 |
| [LeetCode] Average of Levels in Binary Tree (0) | 2021.03.05 |