[Programmers] 가장 긴 펠린드롬

Time Lapse :1hour 0min 0sec

solution.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int solution(string s)
{
for(int i=0;i<s.length();i++){
for(int start=0;start<=i;start++){
bool flag = true;
for(int k=0;k<(s.length()-i)/2;k++){
if(s[k+start]!=s[s.length()-1-i+start-k]){
flag = false;
break;
}
}
if(flag)
return s.length()-i;
}
}
return -1;
}
Author: Song Hayoung
Link: https://songhayoung.github.io/2020/07/30/PS/Programmers/longgestPalindrome/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.