forked from wisdompeak/LeetCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
92d79a2
commit 6c3336d
Showing
1 changed file
with
7 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
### 479.Largest-Palindrome-Product | ||
|
||
两个n位数的数字相乘,得到的最大是2n位数,最小的2n-1位数。但是2n-1位数的数值明显要比2n位数要小,所以有一定的理由相信,答案应该在2n位数里面找。 | ||
|
||
对于所有2n位数的回文数,怎么列举出来?一种方法是:列出所有2n位数,判断是否是回文数;第二种方法,列出所有n位数,构造出对应的2n位数的回文数。显然,后者更加高效。当n最大为8时,回文数是16位,10^16<(2^4)^16<2^64,所以用int64可以装下。 | ||
|
||
有了一个2n位的回文数,再一一尝试所有的n位数(从大往小尝试),如果能除尽,且商仍是n位数,那么这个回文数就是符合题意的。 |