蚂蚁不在线

2018年7月29日

leetcode python 032 识别最长合法括号

摘要: # 给定一个只包含字符'('和')'的字符串,# 找到最长的有效(格式良好)括号子字符串的长度。# 对于“(()”,最长的有效括号子串是“()”,其长度为2。# 另一个例子是“)()())”,其中最长的有效括号子串是“()()”,其长= 4def find_long_valid(s): stack, 阅读全文

posted @ 2018-07-29 21:50 蚂蚁不在线 阅读(195) 评论(0) 推荐(0) 编辑

leetcode python 030 Substring with Concatenation of All Words

摘要: ## 您将获得一个字符串s,以及一个长度相同单词的列表。## 找到s中substring(s)的所有起始索引,它们只包含所有单词,## eg:s: "barfoothefoobarman" words: ["foo", "bar"]## return [0,9].def find_sub(s,wor 阅读全文

posted @ 2018-07-29 14:48 蚂蚁不在线 阅读(122) 评论(0) 推荐(0) 编辑

2018年7月28日

n阶楼梯,一次走1,2,3步,求多少种不同走法

摘要: ##已知n阶楼梯,一次可以迈1,2,3步。求所有走法## 如果要列出走法,时间复杂度太高,O(n)=2**n,前两个函数遍历走法。## 如果只是单纯列出走法数量,就简单多了,也但是很容易内存爆表。 ## n层走法,可以视为n-1层再走一步,n-2层走两步,n-3层走三步。题目都可以按这个思路解决im 阅读全文

posted @ 2018-07-28 16:48 蚂蚁不在线 阅读(2129) 评论(0) 推荐(0) 编辑

2018年7月26日

leetcode python 012 hard 合并k个有序链表

摘要: #[LeetCode] Merge k Sorted Lists 合并k个有序链表(升序)import numpy as npimport timeclass Node(object): def __init__(self,n,next_node=None): self.data=n self.ne 阅读全文

posted @ 2018-07-26 21:34 蚂蚁不在线 阅读(196) 评论(0) 推荐(0) 编辑

leetcode python 011

摘要: ####给定n个非负整数a1,a2,...,an,其中每个表示坐标(i,ai)处的点。##绘制n条垂直线,使得线i的两个端点位于(i,ai)和(i,0)。##找到两条线,它们与x轴一起形成一个容器,这样容器就含有最多的水。##对于容器(i,j)宽j-i,高min(l[i-1],l[j-1]),def 阅读全文

posted @ 2018-07-26 15:57 蚂蚁不在线 阅读(86) 评论(0) 推荐(0) 编辑

leetcode python 010

摘要: #实现正则表达式匹配并支持'.'和'*'。#''匹配任何单个字符。#'*'匹配前面元素的零个或多个。#匹配应覆盖整个输入字符串(非部分)。##Some examples:##isMatch("aa","a") → false##isMatch("aa","aa") → true##isMatch(" 阅读全文

posted @ 2018-07-26 15:33 蚂蚁不在线 阅读(352) 评论(0) 推荐(0) 编辑

2018年7月25日

leetcode python 009

摘要: ##懒得自己做 ## 验证回文数字int0=63435435print(int(str(int0)[::-1])==int) 阅读全文

posted @ 2018-07-25 22:26 蚂蚁不在线 阅读(62) 评论(0) 推荐(0) 编辑

leetcode python 008

摘要: ## 字符串转化为整数## 懒得自己做int0=63435435print(int(int0)) 阅读全文

posted @ 2018-07-25 22:23 蚂蚁不在线 阅读(104) 评论(0) 推荐(0) 编辑

leetcode python 007

摘要: ## 翻转整数def evert(int0): if int0<0: flg=1 else: flg=0 e=int(str(int0)[flg:][::-1]) return e*(-1)**flgint0=-1499851571print(evert(int0)) 阅读全文

posted @ 2018-07-25 21:58 蚂蚁不在线 阅读(237) 评论(0) 推荐(0) 编辑

leetcode python 006

摘要: ## 改为z型字符串def change_to_z(s,n): ## 字符串不能生成完整的区,用空格补全 b=len(s)%(2*n-2) if b!=0: s+=' '*(n*2-2-b) a=len(s)//(2*n-2) lz=[] ## 不同的层 for i in range(n): lg= 阅读全文

posted @ 2018-07-25 21:45 蚂蚁不在线 阅读(307) 评论(0) 推荐(0) 编辑

导航