python Lintcode 刷题(一)
来源:互联网 发布:俄罗斯社交软件vk 编辑:程序博客网 时间:2024/06/11 05:00
按难度或者通过率排序刷题
我的代码如下:
class Solution: # @param n: an integer # @return an integer f(n) def fibonacci(self, n): # write your code here a = 0 b = 1 for i in range(n-1): a, b = b, a+b return a
我的代码如下:
class Solution: """ @param n: An integer as description @return: A list of strings. For example, if n = 7, your code should return ["1", "2", "fizz", "4", "buzz", "fizz", "7"] """ def fizzBuzz(self, n): results = [] for i in range(1, n+1): if i % 15 == 0: results.append("fizz buzz") elif i % 5 == 0: results.append("buzz") elif i % 3 == 0: results.append("fizz") else: results.append(str(i)) return results
class Solution: # @param s: a string # @return: a boolean def isUnique(self, str): # write your code here results = [] new_results = [] for i in str: #字符串变成列表 results.append(i) for i in str: #字符串变成去重的列表 if i not in new_results: new_results.append(i) if results == new_results:#两个比较 return True else: return False
0 0
- python Lintcode 刷题(一)
- lintcode刷题(python)(1)
- lintcode刷题(python)--排列组合
- lintcode刷题(Python)(2)
- lintcode刷题(Python)(3)
- lintcode刷题——python(栈)
- 加一(LintCode)
- lintcode刷题-移动零 python
- LintCode刷题(容易篇 一)
- LintCode算法解析(一)
- lintcode刷题(python)——(4)
- lintcode 加一(Plus One )(Java)
- [LintCode]Fibonacci(Python)
- [LintCode]Anagrams(Python)
- [LintCode]Remove Element(Python)
- LintCode Python 统计数字
- LintCode 字符串置换 python
- LintCode 移动零 python
- 时间、延迟及延缓操作
- Android Hawk数据库 github开源项目
- Spring MVC 同样拦截器。
- 【iOS】被忽略的main函数
- TextView显示图片,阴影,字体加粗,多种颜色字体,自定义字体
- python Lintcode 刷题(一)
- GradientDrawable和AttributeSet自定义控件
- iOS中代理属性为什么要用Weak修饰?
- 扫一扫
- Android开发中常犯的错误有哪些
- linux, bsd
- base operand of '->' has non-pointer type 'JNIEnv {aka _JNIEnv}'和Method 'GetStringUTFChars' could no
- MapperScannerConfigurer在mybatis-spring的妙用
- POJ 3080 Blue Jeans【多串最长子串】