ZigZag Conversion(math)

QuestioThe 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 legibilityP A H A P L S I I Y I And then read line by line: "PAHNAPLSIIGYIR"Write the code that will take a string and make this conversion given a number of rowsstring convert(string text, int nRows);convert("PAYPAL...阅读全文

翻转整型数(水题)

正题Reverse digits of an integer.Example1: x = 123, return 32Example2: x = -123, return -32思考改题为简单难度(水题),根据题意可以依次取到给定的整型数x的最高位到最低的数,然后依次将其乘10的x次幂后进行累加即可得到结果。这里,要知道32位的整型一共有九个0,故声明i=1000000000;代码原题:https://leetcode.com/problems/reverse-integer/description阅读全文

最长回文字符串题解(动态规划)

LeetCode正题Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.ExampleInput: "babad"Output: "bab"Note: "aba" is also a valid answer.ExampleInput: "cbbd"Output: "bb"思考回文字符串即正向顺序和反向顺序的字幕排序是一致的字段串。题的大意为寻找一个指定字符串中的最长的回文字符串。首选,暴力解法需要遍历所有子串并判断子串是否为回文字符串。假设给定字符串长度n,那么子串的总数为​n(n+1)/2(即1 2 3 ... n的和),即需要O(n^2),然后判断每个子串是否为回文字符串的时间复杂度为O(n),即总共需要...阅读全文