problem 5,6,7
###5. Longest Palindromic Substring
Medium
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.
Example 1:
1 | |
Example 2:
1 | |
要实现回文,最简单的思路就是从中间向两边走,
这个问题的难点在于如何定义中点来处理奇数和偶数回文问题
“ababa”
“cccababa”
1 | |
###6. ZigZag Conversion
Medium
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)
1 | |
And then read line by line: "PAHNAPLSIIGYIR"
Write the code that will take a string and make this conversion given a number of rows:
1 | |
Example 1:
1 | |
Example 2:
1 | |
这个问题的思路在于分组处理,如何寻找分组的规律是重点
N=3 4个一循环
4n+1 4n+3一组
N=4 6个一循环
6n+1 6n+5一组 6n+2 6n+4
N=5 8个一循环
+1 +7 +2 +6 +3 +5
1 | |
7. Reverse Integer
Easy
Given a 32-bit signed integer, reverse digits of an integer.
Example 1:
1 | |
Example 2:
1 | |
Example 3:
1 | |
1 | |