palindrome

The definition of palindromes is that the forward and reverse reading is the same, for example: 121, 12321, 1221, 345543, the first reaction is to convert into a string, and then intercept, reverse, contrast, AM I lost…

First exclude which numbers are not palindromes:

1. Negative numbers are definitely not.

2. Anything with a zero at the end is definitely not.

The comparison method can refer to the partial algorithm of integer inversion, reverse X, and compare whether two numbers are equal when the inversion reaches half, that is, result <= X.


Roman numerals

After seeing the big guy’s solution, the core is:

The number on the left is less than the number on the right, minus the number on the left.

The number on the left is greater than or equal to the number on the right, plus the number on the left.

I can just add the last digit.

For I, V, X, L, C, D, and M in the text, you can use switch to return the corresponding number.


Longest public prefix

Method 1: Horizontal comparison: use a variable to represent the common prefix of the current N elements. For example, compare the 0 element and the 1 element first to find out the common part. Then compare the common part with the second element, find the common part, compare the common part with the third element, and so on.

So how do you find the common part? Compare str.charat (I).

If there are different characters in the second column, return the substring from 0 to the current index

Method 3: divide and conquer: first divide the array, and then divide each subarray, and then divide each array again (recursion can be used here), until each element is divided into a subarray, and then find the common prefix of two elements, and then recurse to the upper layer, and then find the common prefix of the second layer.

Let’s call it a day and see you tomorrow!