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
- linux
- MySQL
- rpg server
- screencapture
- SDK upgrade
- Camera Movement
- --watch
- spread 연산자
- Git
- Unity IAP
- react
- Spring Boot
- docker
- critical rendering path
- unity
- server
- Google Developer API
- mongoDB
- express
- css framework
- nodejs
- Unity Editor
- Packet Network
- OverTheWire
- java
- Google Refund
- Digital Ocean
- draganddrop
- Camera Zoom
- springboot
Archives
- Today
- Total
우당탕탕 개발일지
[프로그래머스] Level 3. 가장 긴 팰린드롬 본문
https://school.programmers.co.kr/learn/courses/30/lessons/12904
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
- 팰린드롬에는 2가지가 있다.
- 홀수로 대칭인것 "abcba" >> getPalindrome() 함수에서 max길이를 구한다.
- 짝수로 대칭인것 "abccba" >> getEvenPalindrom() 함수에서 max길이를 구한다.
#include <iostream>
#include <string>
using namespace std;
int getPalindrome(string s, int i){
int value = 1;
int index =1;
while(i-index >=0 && i+index < s.size() && s[i-index] == s[i+index]){
value = index*2+1;
index++;
}
return value;
}
int getEvenPalindrome(string s, int i) {
int value = 0;
int index = 0;
while (i - index >= 0 && i + 1 + index < s.size() && s[i - index] == s[i + 1 + index]) {
value = (index + 1) * 2;
index++;
}
return value;
}
int solution(string s)
{
int answer=1;
for(int i=0; i<s.size(); i++){
answer= max(answer, getPalindrome(s,i));
answer= max(answer, getEvenPalindrome(s,i));
}
return answer;
}
'Algorithm(c++) > Level 3' 카테고리의 다른 글
[프로그래머스] Level 3. 디스크 컨트롤러 (0) | 2025.03.09 |
---|---|
[프로그래머스] Level 3. 입국 심사 (0) | 2025.03.09 |
[프로그래머스] Level 3. 연속 펄스 부분 (0) | 2025.03.08 |
[프로그래머스] Level 3. 가장 먼 노드 (0) | 2025.03.05 |
[프로그래머스] Level 3. 징검다리 건너기 (0) | 2025.03.03 |