摘要: 在上一篇随笔“使用快速傅里叶变换计算大整数乘法”中,已经讲述了使用快速傅里叶变换计算大整数乘法的原理。在这一篇随笔中,我们就使用快速傅里叶变换来实现一个提供任意精度的算术运算的静态类:BigArithmetic。 下面就是 BigArithmetic 类源程序代码: 1 usin... 阅读全文
posted @ 2016-04-28 22:47 Free_Open 阅读(785) 评论(0) 推荐(0) 编辑
摘要: karatsuba乘法 Karatsuba乘法是一种快速乘法。此算法在1960年由Anatolii Alexeevitch Karatsuba 提出,并于1962年得以发表。[1] 此算法主要用于两个大数相乘。普通乘法的复杂度是n2,而Karatsuba算法的复杂度仅为3nlog3... 阅读全文
posted @ 2016-04-28 22:46 Free_Open 阅读(795) 评论(0) 推荐(0) 编辑
摘要: 我们知道,两个 N 位数字的整数的乘法,如果使用常规的算法,时间复杂度是 O(N2)。然而,使用快速傅里叶变换,时间复杂度可以降低到 O(N logN loglogN)。 假设我们要计算以下两个 N 位数字的乘积: a = (aN-1aN-2...a1a0)10 = aN-1x10N... 阅读全文
posted @ 2016-04-28 22:05 Free_Open 阅读(1022) 评论(0) 推荐(0) 编辑
摘要: Longest Common Prefix My Submissions Difficulty: Easy Write a function to find the longest common prefix string amongst an array of string... 阅读全文
posted @ 2016-04-28 20:20 Free_Open 阅读(93) 评论(0) 推荐(0) 编辑
摘要: Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the tw... 阅读全文
posted @ 2016-04-28 19:23 Free_Open 阅读(106) 评论(0) 推荐(0) 编辑
摘要: ‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element.The matching should cover the entire input string (not pa... 阅读全文
posted @ 2016-04-28 17:48 Free_Open 阅读(145) 评论(0) 推荐(0) 编辑
摘要: easy 21. Merge Two Sorted Lists Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together t... 阅读全文
posted @ 2016-04-28 13:31 Free_Open 阅读(99) 评论(0) 推荐(0) 编辑
摘要: Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.思路:先构造罗马与数字的映射,接着对给定的字符串从头开始进行最长匹配,... 阅读全文
posted @ 2016-04-28 13:21 Free_Open 阅读(132) 评论(0) 推荐(0) 编辑
摘要: 回文数的判定,不使用额外的空间 Determine whether an integer is a palindrome. Do this without extra space.思路:将一个整数逆转,判定和原来的数相不相等 注意负数一定不是回文数#define IMAX nume... 阅读全文
posted @ 2016-04-28 12:11 Free_Open 阅读(145) 评论(0) 推荐(0) 编辑
摘要: 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 fi... 阅读全文
posted @ 2016-04-28 10:21 Free_Open 阅读(118) 评论(0) 推荐(0) 编辑