Category Archives: String

Longest Palindromic Substring

Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. C++: 01 class Solution { 02 public: 03     string longestPalindrome(string s) { 04      … Continue reading

Posted in Array and linked list, String | Leave a comment

ZigZag Conversion

The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility) P A H N A P L S I I G … Continue reading

Posted in Array and linked list, String | Leave a comment

String to Integer (atoi)

Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases. Notes: It is intended for this problem to be … Continue reading

Posted in Number trick, String | Leave a comment

Regular Expression Matching

Implement regular expression matching with support for ‘.’ and ‘*’. ‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element. The matching should cover the entire input string (not partial). The function prototype should be: bool isMatch(const char *s, … Continue reading

Posted in Recursive, String | Leave a comment

Integer to Roman

Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. C++: 01 class Solution { 02 public: 03     string intToRoman(int num) { 04         // Start typing your … Continue reading

Posted in Number trick, String | Leave a comment

Roman to Integer

Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. C++: 01 class Solution { 02 public: 03     int romanToInt(string s) { 04         // Start typing your … Continue reading

Posted in Number trick, String | Leave a comment

Substring with Concatenation of All Words

You are given a string, S, and a list of words, L, that are all of the same length. Find all starting indices of substring(s) in S that is a concatenation of each word in L exactly once and without any intervening … Continue reading

Posted in Array and linked list, Hashtable and Map, String | Leave a comment