随笔分类 -  codewar刷题笔记

给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效。
摘要:给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效。 有效字符串需满足: 左括号必须用相同类型的右括号闭合。左括号必须以正确的顺序闭合。注意空字符串可被认为是有效字符串。 class Solution: def isValid(self, s): if le 阅读全文

posted @ 2020-06-15 16:23 阿虾 阅读(3669) 评论(0) 推荐(0)

罗马数字转整型
摘要:# 将罗马数字转换成整型# class Solution:# def romanToInt(self, s):# d = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}# num = 0# for i in rang 阅读全文

posted @ 2020-06-09 13:42 阿虾 阅读(183) 评论(0) 推荐(0)

判断回文数
摘要:class Solution: def isPalindrome(self, x): if str(x).startswith('-'): return False else: a = str(x) b = a[::-1] if a == b: return True else: return Fa 阅读全文

posted @ 2020-06-09 13:01 阿虾 阅读(134) 评论(0) 推荐(0)

返回数值数组的“峰值”(或局部最大值)的位置和值
摘要:题目描述: # In this kata, you will write a function that returns the positions and the values of the "peaks" (or local maxima) of a numeric array.## For e 阅读全文

posted @ 2020-04-20 13:31 阿虾 阅读(410) 评论(0) 推荐(0)

找到数组或整数列表中连续子序列的最大和
摘要:题目描述: The maximum sum subarray problem consists in finding the maximum sum of a contiguous subsequence in an array or list of integers: maxSequence([- 阅读全文

posted @ 2020-04-15 14:18 阿虾 阅读(373) 评论(0) 推荐(0)

编写一个调用的函数,该函数接受一个括号字符串,并确定括号的顺序是否有效
摘要:题目描述: Write a function called that takes a string of parentheses, and determines if the order of the parentheses is valid. The function should return 阅读全文

posted @ 2020-04-13 16:48 阿虾 阅读(619) 评论(0) 推荐(0)

返回列表中最长的连续字符串
摘要:题目描述: # You are given an array strarr of strings and an integer k. Your task is to return the first longest string consisting of k consecutive strings 阅读全文

posted @ 2020-04-10 12:18 阿虾 阅读(476) 评论(0) 推荐(0)

输入一个数字,求每一位相加之和
摘要:题目描述: # In this kata, you must create a digital root function.## A digital root is the recursive sum of all the digits in a number. Given n, take the 阅读全文

posted @ 2020-04-07 20:06 阿虾 阅读(523) 评论(0) 推荐(0)

判断一个数是否为素数
摘要:我的解答: import mathdef is_prime(n): if n > 1: if n == 2: return True if n % 2 == 0: return False for current in range(3, int(math.sqrt(n) + 1), 2): if n 阅读全文

posted @ 2020-04-07 16:57 阿虾 阅读(240) 评论(0) 推荐(0)

编写一个函数,它接受一个或多个单词的字符串,并返回相同的字符串,但所有五个或多个字母的单词都颠倒过来
摘要:题目描述: # Write a function that takes in a string of one or more words, and returns the same string, but with all five or more letter words reversed (Ju 阅读全文

posted @ 2020-04-07 16:53 阿虾 阅读(889) 评论(0) 推荐(0)

判断10步能不能回到原点
摘要:题目描述: # You live in the city of Cartesia where all roads are laid out in a perfect grid.# You arrived ten minutes too early to an appointment, so you 阅读全文

posted @ 2020-04-05 23:09 阿虾 阅读(219) 评论(0) 推荐(0)

完成方法/函数,以便将破折号/下划线分隔的单词转换为驼峰式大小写
摘要:题目描述: # Complete the method/function so that it converts dash/underscore delimited words into camel casing. The first word within the output should be 阅读全文

posted @ 2020-04-05 22:06 阿虾 阅读(405) 评论(0) 推荐(0)

求公共汽车上的人数
摘要:题目描述: # Number of people in the bus# There is a bus moving in the city, and it takes and drop some people in each bus stop.## You are provided with a 阅读全文

posted @ 2020-04-05 21:12 阿虾 阅读(181) 评论(0) 推荐(0)

写一个函数,返回不同的计数
摘要:题目描述: # Write a function that will return the count of distinct# case-insensitive alphabetic characters and numeric digits t# hat occur more than once 阅读全文

posted @ 2020-04-05 20:55 阿虾 阅读(147) 评论(0) 推荐(0)

对一个数的每一位数字求平方
摘要:题目描述: # Welcome. In this kata, you are asked to square every digit of a number.# For example, if we run 9119 through the function, 811181 will come ou 阅读全文

posted @ 2020-04-05 20:16 阿虾 阅读(297) 评论(0) 推荐(0)

写一个以整数为输入的函数, 并返回二进制中等于1的位的数目
摘要:题目描述: # Write a function that takes an integer as input,# and returns the number of bits that are equal to one in the binary# representation of that n 阅读全文

posted @ 2020-04-05 20:06 阿虾 阅读(491) 评论(0) 推荐(0)

Array.diff
摘要:题目描述:# Your goal in this kata is to implement a difference function, which subtracts one list from another and returns the result.## It should remove 阅读全文

posted @ 2020-04-05 19:46 阿虾 阅读(173) 评论(0) 推荐(0)

ATM机允许4位或6位密码,而密码只能包含4位或6位数字。 如果函数传递了一个有效的PIN字符串,返回true,否则返回false。
摘要:题目描述: ATM machines allow 4 or 6 digit PIN codes and PIN codes cannot contain anything but exactly 4 digits or exactly 6 digits. If the function is pas 阅读全文

posted @ 2020-04-05 16:34 阿虾 阅读(384) 评论(0) 推荐(0)

替换字符串中的字符为“(” 或“)”
摘要:题目描述:# The goal of this exercise is to convert a string to a new string where each character# in the new string is "(" if that character appears only 阅读全文

posted @ 2020-04-05 16:33 阿虾 阅读(366) 评论(0) 推荐(0)

导航