刷题
燕儿哥python
匠心独具
展开
-
python算法:Longest Common Subsequence
Write a function called LCS that accepts two sequences and returns the longest subsequence common to the passed in sequences.SubsequenceA subsequence is different from a substring. The terms of a subs...原创 2018-05-09 15:50:38 · 913 阅读 · 0 评论 -
python 算法题:Sum of two lowest positive integers
Create a function that returns the sum of the two lowest positive numbers given an array of minimum 4 integers. No floats or empty arrays will be passed.For example, when an array is passed like [19, ...原创 2018-04-27 20:10:19 · 558 阅读 · 0 评论 -
PYTHON算法题:Exes and Ohs
Check to see if a string has the same amount of 'x's and 'o's. The method must return a boolean and be case insensitive. The string can contain any char.Examples input/output:XO("ooxx") => trueXO("...原创 2018-04-28 10:12:53 · 426 阅读 · 0 评论 -
python错误提示:AttributeError: 'NoneType' object has no attribute 'append'
写python程序时遇到的错误提示: AttributeError: 'NoneType' object has no attribute 'append'例如你定义了空list,想讲元素加进去l=[]m=''.join.s[i:i+k]l = l.append(m)请注意:l = l.append(m) 是不对的,【与之区分的是常用的a+=1】l.a...原创 2018-04-28 15:45:51 · 36948 阅读 · 5 评论 -
python算法:Consecutive strings
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 taken in the array.#Example: longest_consec(["zone", "abi...原创 2018-04-28 17:47:32 · 554 阅读 · 0 评论 -
python算法:Find the divisors!
Create a function named divisors/Divisors that takes an integer and returns an array with all of the integer's divisors(except for 1 and the number itself). If the number is prime return the string '(...原创 2018-04-28 18:12:49 · 492 阅读 · 0 评论 -
python算法:Beginner Series #3 Sum of Numbers
Given two integers a and b, which can be positive or negative, find the sum of all the numbers between including them too and return it. If the two numbers are equal return a or b.Note: a and b are no...原创 2018-04-28 20:42:37 · 617 阅读 · 0 评论 -
python 算法:Descending Order
Your task is to make a function that can take any non-negative integer as a argument and return it with its digits in descending order. Essentially, rearrange the digits to create the highest possible...原创 2018-04-28 22:21:39 · 1696 阅读 · 0 评论 -
python算法:Convert string to camel case
Complete the method/function so that it converts dash/underscore delimited words into camel casing. The first word within the output should be capitalized only if the original word was capitalized.Exa...原创 2018-04-29 21:54:53 · 1032 阅读 · 0 评论 -
python 算法:Reverse words
刷到现在的感受是:不会的命令一定及时Google哈哈哈哈哈Write a reverseWords function that accepts a string a parameter, and reverses each word in the string. Any spaces in the string should be retained.Example:reverse_words("T...原创 2018-04-29 22:12:20 · 2480 阅读 · 0 评论 -
一道python面试题:不用sort()对list实现排序
这题偶然看到的,典型啊,值得马克一记!list=[2,3,5,4,9,6,8,7,1],从小到大排序,不许用sort,输出[1,2,3,4,5,6,,7,8,9]结题思路: 利用min()方法求出最小值,原列表删除最小值,新列表加入最小值,递归调用获取最小值的函数,反复操作list=[2,3,5,4,9,6,8,7,1]ll=[]if len(list)>0: m=min(...原创 2018-04-29 22:45:51 · 6873 阅读 · 5 评论 -
python 算法:罗马数字转化
class Solution: def romanToInt(self, s): """ :type s: str :rtype: int """ d={'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000} sum=0 for i...原创 2018-05-14 20:05:06 · 607 阅读 · 0 评论 -
pythion 算法题:Find the missing letter
#Find the missing letterWrite a method that takes an array of consecutive (increasing) letters as input and that returns the missing letter in the array.You will always get an valid array. And it will...原创 2018-04-27 19:55:59 · 445 阅读 · 0 评论 -
PYTHON 算法题:Categorize New Member
The Western Suburbs Croquet Club has two categories of membership, Senior and Open. They would like your help with an application form that will tell prospective members which category they will be pl...原创 2018-04-27 19:52:25 · 284 阅读 · 0 评论 -
python算法:ROT13
How can you tell an extrovert from an introvert at NSA? Va gur ryringbef, gur rkgebireg ybbxf ng gur BGURE thl'f fubrf.I found this joke on USENET, but the punchline is scrambled. Maybe you can deciph...原创 2018-05-09 20:12:14 · 3092 阅读 · 0 评论 -
python算法:Going to zero or to infinity?
Consider the following numbers (where n! is factorial(n)):u1 = (1 / 1!) * (1!)u2 = (1 / 2!) * (1! + 2!)u3 = (1 / 3!) * (1! + 2! + 3!)un = (1 / n!) * (1! + 2! + 3! + ... + n!)Which will win: 1 / n! or ...原创 2018-05-09 20:45:14 · 378 阅读 · 0 评论 -
python算法:Which are in?
Given two arrays of strings a1 and a2 return a sorted array r in lexicographical order of the strings of a1 which are substrings of strings of a2.#Example 1: a1 = ["arp", "live", "strong"]a2 = ["livel...原创 2018-05-03 19:52:37 · 477 阅读 · 0 评论 -
python 算法:Valid Parentheses
Write a function called that takes a string of parentheses, and determines if the order of the parentheses is valid. The function should return true if the string is valid, and false if it's invalid.E...原创 2018-05-04 20:13:16 · 479 阅读 · 0 评论 -
python 算法:Product of consecutive Fib numbers
The Fibonacci numbers are the numbers in the following integer sequence (Fn):0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, ...such as:F(n) = F(n-1) + F(n-2) with F(0) = 0 and F(1) = 1.Given a num...原创 2018-05-05 10:22:31 · 588 阅读 · 0 评论 -
python算法:Palindrome chain length
Number is a palindrome if it is equal to the number with digits in reversed order. For example, 5, 44, 171, 4884 are palindromes and 43, 194, 4773 are not palindromes.Write a method palindrome_chain_l...原创 2018-05-11 20:20:06 · 400 阅读 · 0 评论 -
python算法练习:寻找下一个完全平方数
题目大意:Return the next square if sq is a square, -1 otherwise我自己最开始写的:import mathdef find_next_square(sq): a=math.sqrt(sq)#a的类型是float# print(type(a)) if int(a)==a: return (a+1)**2...原创 2018-04-27 13:43:33 · 1069 阅读 · 0 评论 -
python算法练习题:去除列表里的字符串
#去除列表里的字符串#去除列表里的字符串def filter_list(l): #return a new list with the strings filtered out ll=[] for i in range (len(l)): if type(l[i]) is int: ll.append(l[i]) print(l...原创 2018-04-27 15:40:00 · 1959 阅读 · 0 评论 -
python算法:Equal Sides Of An Array
You are going to be given an array of integers. Your job is to take that array and find an index N where the sum of the integers to the left of N is equal to the sum of the integers to the right of N....原创 2018-05-12 11:21:38 · 593 阅读 · 1 评论 -
python算法:Dubstep
Polycarpus works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them.Le...原创 2018-05-12 11:42:47 · 675 阅读 · 0 评论 -
python算法:Buying a car
A man has a rather old car being worth $2000. He saw a secondhand car being worth $8000. He wants to keep his old car until he can buy the secondhand one.He thinks he can save $1000 each month but the...原创 2018-05-12 14:19:33 · 202 阅读 · 0 评论 -
python算法:最长公共前缀
class Solution: def longestCommonPrefix(self, strs): """ :type strs: List[str] :rtype: str """ if len(strs)==0: return '' x=0 y=...原创 2018-05-14 20:37:45 · 412 阅读 · 0 评论