-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path가장 긴 팰린드롬.swift
More file actions
34 lines (30 loc) · 834 Bytes
/
가장 긴 팰린드롬.swift
File metadata and controls
34 lines (30 loc) · 834 Bytes
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
32
33
34
//
// 가장 긴 팰린드롬.swift
//
//
// Created by chihoooon on 2022/02/14.
//
import Foundation
func solution(_ s: String) -> Int {
var answer = 1
let targetString = s.map { $0 }
for i in 0..<targetString.count - 1 {
for j in 0..<targetString.count - i {
let length = targetString.count - j - i
let start = i
let end = targetString.count - j - 1
var flag = true
for k in 0..<length / 2 {
if targetString[start + k] != targetString[end - k] {
flag = false
break
}
}
if flag {
answer = max(answer, length)
break
}
}
}
return answer
}