Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Algorithm] StrSymmetryPoint 문제 풀이 #160

Closed
hwangJi-dev opened this issue Mar 26, 2023 · 0 comments
Closed

[Algorithm] StrSymmetryPoint 문제 풀이 #160

hwangJi-dev opened this issue Mar 26, 2023 · 0 comments
Assignees

Comments

@hwangJi-dev
Copy link
Owner

hwangJi-dev commented Mar 26, 2023

💬 문제

https://app.codility.com/programmers/trainings/4/str_symmetry_point/


💬 Idea

  • 중간 인덱스까지 비교하며 같지 않다면 return -1, 같다면 mid를 리턴한다.

💬 풀이

public func solution(_ S : inout String) -> Int {
    if S.count % 2 == 0 { return -1 }
    
    let mid = S.count / 2
    var start = 0
    var end = S.count - 1
    let s = Array(S).map({ String($0) })
    
    while start < mid {
        if s[start] != s[end] {
            return -1
        }
        
        start += 1
        end -= 1
    }
    
    return mid
}

효율성 0점 풀이 : https://app.codility.com/demo/results/trainingDY7DPQ-PFH/

100점 풀이 : https://app.codility.com/demo/results/trainingZNRGGS-24G/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant