File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change 1+ #include <string.h>
2+ #include <stdlib.h>
3+ #include <ctype.h>
4+ #include <stdbool.h>
5+
6+ /*
7+ 문자열 s의 길이를 N이라고 할 때
8+
9+ 시간복잡도
10+
11+ for문 두 번 돌려서 2N
12+
13+ => N
14+ =================
15+ 공간복잡도
16+
17+ 두 번 복사하면서 2N
18+
19+ => N
20+ */
21+
22+ bool isPalindrome (char * s ) {
23+ char * alnumDup = calloc (strlen (s ) + 1 , sizeof (char ));
24+ char * revDup ;
25+ int j = 0 ;
26+
27+ for (int i = 0 ; s [i ]; i ++ )
28+ {
29+ if (isalnum (s [i ]))
30+ {
31+ alnumDup [j ] = tolower (s [i ]);
32+ j ++ ;
33+ }
34+ }
35+ revDup = calloc (strlen (alnumDup ) + 1 , sizeof (char ));
36+ j = 0 ;
37+ for (int i = strlen (alnumDup ); i ; i -- )
38+ revDup [j ++ ] = alnumDup [i - 1 ];
39+ if (strcmp (alnumDup , revDup ))
40+ {
41+ free (alnumDup );
42+ free (revDup );
43+ return (false);
44+ }
45+ else
46+ {
47+ free (alnumDup );
48+ free (revDup );
49+ return (true);
50+ }
51+ }
You can’t perform that action at this time.
0 commit comments