- 博客(6)
- 收藏
- 关注
原创 关于python快速求正整数幂的研究
一直以来,快速求幂屡屡出现在各种题目中(内置pow直接返回?),虽然关于python实现快速求幂可能有很多版本,大部分基于原始C语言版本的生硬的python版本,我也背过一本《高效算法》里的快速求幂,然而其趋向C过于严重,以至于过不了多久全然忘记,或者可操作性极差,需要反复翻阅,难得求职期间闲暇,故对于python版本的快速求正整数幂稍作研究。 《高效算法》版本: def fast_expo...
2019-01-27 21:02:13
933
原创 Rational Arithmetic 有理数四则运算,Python
题目如下: For two rational numbers, your task is to implement the basic arithmetics, that is, to calculate their sum, difference, product and quotient. 输入描述: Each input file contains one test case, wh...
2018-09-07 10:54:48
591
原创 459. Repeated Substring Pattern //重复的子字符串 Python
给定一个非空的字符串,判断它是否可以由它的一个子串重复多次构成。给定的字符串只含有小写英文字母,并且长度不超过10000。 示例 1: 输入: "abab" 输出: True 解释: 可由子字符串 "ab" 重复两次构成。 示例 2: 输入: "aba" 输出: False 示例 3: 输入: "abcabcabcabc" 输出: True 解释: 可由子字符串 "...
2018-08-28 23:55:06
1418
原创 686. Repeated String Match//重复叠加字符串匹配 Python
给定两个字符串 A 和 B, 寻找重复叠加字符串A的最小次数,使得字符串B成为叠加后的字符串A的子串,如果不存在则返回 -1。 举个例子,A = "abcd",B = "cdabcdab"。 答案为 3, 因为 A 重复叠加三遍后为 “abcdabcdabcd”,此时 B 是其子串;A 重复叠加两遍后为"abcdabcd",B 并不是其子串。 注意: A 与 B 字符串的长度在1和100...
2018-08-28 23:42:19
448
原创 840. Magic Squares In Grid Python题解
A 3 x 3 magic square is a 3 x 3 grid filled with distinct numbers from 1 to 9 such that each row, column, and both diagonals all have the same sum. Given an grid of integers, how many 3 x 3 "magic sq...
2018-08-01 19:59:23
757
原创 最长连续序列O(n)解法,Python
Leetcode上的一道习题:Given an unsorted array of integers, find the length of the longest consecutive elements sequence.Your algorithm should run in O(n) complexity.Example:Input: [100, 4, 200, 1, 3, 2] Outp...
2018-06-27 16:05:59
2186
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人