From the course: Nail Your C# Interview
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Solution: Developing a palindrome checker - C# Tutorial
From the course: Nail Your C# Interview
Solution: Developing a palindrome checker
(music) - [Instructor] Let's implement a palindrome checker. A palindrome is a word or phrase which reads the same backwards as it does forwards. To start, we'll create a lowercased version of the original string and normalize it to a common form. Then, we'll build a reverse string by iterating through the normalized string and adding each character in reverse. We're using a StringBuilder because it lets us represent a mutable string of characters. The regular string data type is not mutable, so, since we're doing so many mutations, it would not be efficient to use it. Let's iterate through the string. At the end of our function, we'll check if the reverse string equals our normalized string. If they're equal, then the original string must be a palindrome. Let's see if this works. Our implementation works as expected, but we could make it more efficient. In fact, we could eliminate the creation of strings almost entirely by cleverly checking certain indices of the original string. We…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Concatenate strings with different methods2m 49s
-
(Locked)
Normalize string input4m 55s
-
(Locked)
Validate string input6m 47s
-
(Locked)
Access data from strings7m 30s
-
(Locked)
Create algorithm-driven strings in C#7m
-
(Locked)
Solution: Developing a palindrome checker3m 38s
-
(Locked)
Solution: Reverse each word2m 15s
-
-
-
-
-