public class Solution
    {
        public int LargestPalindrome(int n)
        {
            if (n == 1) return 9;
            int max = (int)Math.Pow(10, n) - 1;
            for (int v = max - 1; v > max / 10; v--)
            {
                StringBuilder sb = new StringBuilder();
                foreach (var c in v.ToString().Reverse())
                {
                    sb.Append(c);
                }
                long u = Convert.ToInt64(v.ToString() + sb.ToString());
                for (long x = max; x * x >= u; x--)
                    if (u % x == 0)
                        return (int)(u % 1337);
            }
            return 0;
        }
    }

https://leetcode.com/problems/largest-palindrome-product/description/

posted on 2017-09-25 18:55  Sempron2800+  阅读(132)  评论(0编辑  收藏  举报