28. Implement strStr() leetcode Python new season 2016
2016-01-12 11:43
417 查看
Implement strStr().
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
Show Company Tags
Show Tags
Show Similar Problems
python string is immutable .. have to do sth not optimized. may change it in the future.
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
Show Company Tags
Show Tags
Show Similar Problems
python string is immutable .. have to do sth not optimized. may change it in the future.
class Solution(object): def strStr(self, haystack, needle): """ :type haystack: str :type needle: str :rtype: int """ if haystack == "" and needle == "": return 0 if haystack == "" and needle != "": return -1 if needle == "": return 0 newstr = haystack.split(needle) if len(newstr[0]) == len(haystack): return -1 return len(newstr[0])
相关文章推荐
- WIN10 64bit python3.4 安装 numpy scipy matplotlib
- python代码段
- 27. Remove Element leetcode python 2016 new season
- Python 连接 MySQL数据库
- python数字图像处理(6):图像的批量处理
- python操作MySQL数据库
- python遍历文件夹并实现分级缩进显示
- Python -- str 类
- python中if __name__ == '__main__': 的解析
- python生成随机数组
- Python异常处理
- Python中的method
- Python下划线与命名规范
- Python开发Webservice(SOAP)
- WIN10 64bit python2.7 安装 numpy scipy matplotlib
- 【极客学院】-python学习笔记-3-单线程爬虫 (request安装遇到问题及解决,应用requests提取信息)
- Python系列之 - Collections系列
- 从0到1 python简易计算器
- Cairo Tutorial for Python Programmers
- 堆排序(Python版)