2015年4月3日金曜日

Lesson 99: StrSymmetryPoint (Str Symmetry Point)

Lesson 99: StrSymmetryPoint (Str Symmetry Point)
https://codility.com/programmers/lessons/14

This is a simple problem. We only scan from both ends.
If the scanning positions reached the same position, that's the
answer.









int solution(char *S) { int len = strlen(S); if (len % 2 == 0){ return -1; } int l = 0; int r = len - 1; while (l < r){ if (S[l] != S[r]){ return -1; } l++; r--; } return l; }

0 件のコメント:

コメントを投稿