
codewars
尉迟海棠
这个作者很懒,什么都没留下…
展开
-
[codewars][Python] 移动首字母
题目:把每个单词的首字母移到单词结尾,并添加“ay”,输入新的字符串Smart Answer:string.isalnum()方法 -- 如果 string 至少有一个字符并且所有字符都是字母或数字则返回 True,否则返回 Falsedef pig_it(text): lst = text.split() return ' '.join( [word[1:] +...原创 2019-10-30 10:40:45 · 715 阅读 · 1 评论 -
[codewars][Python] Delete occurrences of an element if it occurs more than n times
TaskGiven a list lst and a number N, create a new list that contains each number of lst at most N times without reordering. For example if N = 2, and the input is [1,2,3,1,2,1,2,3], you take [1,2,3,...原创 2019-10-28 16:16:15 · 275 阅读 · 0 评论 -
[codewars][Python] Are they the "same"? -- 判断一个列表中元素的平方是否是另一个列表中的元素
题目:一个列表array1, 一个列表array2,如果array2中的每个元素都是array1中元素的平方,则返回true,否则返回falseValid arraysa = [121, 144, 19, 161, 19, 144, 19, 11] b = [121, 14641, 20736, 361, 25921, 361, 20736, 361]comp(a, b)ret...原创 2019-10-28 11:19:21 · 315 阅读 · 0 评论 -
[codewars][Python] BitCounting - 十进制转二进制,并返回二进制中1的个数
题目:把十进制转成二进制,并返回其中1的个数比如: 1234 -->10011010010 --> 5My Answer:思路: 把二进制数转成字符串形式,再把每一位取出来相加,得到的数就是1的个数def countBits(n): #先把输入的整数转换成二进制数 b = bin(n) ### bin方法返回的值是字符串形式...原创 2019-10-28 10:15:45 · 586 阅读 · 0 评论 -
[codewars][Python] Find the unique number
题目:找出列表中唯一一个不重复的元素There is an array with some numbers. All numbers are equal except for one. Try to find it!find_uniq([ 1, 1, 1, 2, 1, 1 ]) == 2find_uniq([ 0, 0, 0.55, 0, 0 ]) == 0.55It’s gua...原创 2019-10-16 13:56:38 · 432 阅读 · 0 评论 -
[codewars][Python] 把列表中的奇数值按照从小到大的方式排列,偶数值的位置不变
my code:基本思想:1) 把相邻的两个奇数元素进行比较,大的向后移2)按照这个方式执行奇数元素个数次def sort_array(source_array): # Return a sorted array. num_odd = 0 for i in source_array: if i %2 !=0: num...原创 2019-10-15 17:50:39 · 1707 阅读 · 0 评论 -
[codewars][Python] Get the Middle Character
题目:You are going to be given a word. Your job is to return the middle character of the word. If the word's length is odd, return the middle character. If the word's length is even, return the middle...原创 2019-10-15 15:22:29 · 289 阅读 · 0 评论 -
[codewars] [Python]Which are in?
题目: 有两个数组,a1,a2, 返回一个数组r,r中保存的元素为a1中的字符串是a2中字符串的子集的部分。Given two arrays of stringsa1anda2return a sorted arrayrin lexicographical order of the strings ofa1which are substrings of strings of...原创 2019-10-15 13:26:44 · 188 阅读 · 0 评论 -
[codewars] TripleDouble
题目:Write a functionTripleDouble(long num1, long num2)which takes numbersnum1andnum2and returns1if there is a straight triple of a number at any place innum1and also a straight double o...原创 2019-07-17 20:26:53 · 287 阅读 · 0 评论 -
[codewars] Tribonacci序列,将数组中的三位数顺序相加,产生第四位数
Well met with Fibonacci bigger brother, AKA Tribonacci.As the name may already reveal, it works basically like a Fibonacci, but summing the last 3 (instead of 2) numbers of the sequence to generate...原创 2019-07-11 10:01:02 · 514 阅读 · 0 评论 -
[codewars][Java] 翻译摩斯码
In this kata you have to write a simpleMorse codedecoder. While the Morse code is now mostly superceded by voice and digital data communication channels, it still has its use in some applications a...原创 2019-07-10 15:56:26 · 729 阅读 · 0 评论