随笔分类 -  leetcode

摘要:class Solution(object): def romanToInt(self, s): """ :type s: str :rtype: int """ lista={'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000} Valu... 阅读全文
posted @ 2019-03-10 19:50 anobscureretreat 阅读(165) 评论(0) 推荐(0) 编辑
摘要:class Solution(object): def intToRoman(self, num): """ :type num: int :rtype: str """ if num == 0: return "" if num >= 1000: ... 阅读全文
posted @ 2019-03-10 19:40 anobscureretreat 阅读(241) 评论(0) 推荐(0) 编辑
摘要:class Solution(object): def isPalindrome(self, x): """ :type x: int :rtype: bool """ s=str(x) if(s==s[::-1]): return True els... 阅读全文
posted @ 2019-03-10 18:07 anobscureretreat 阅读(100) 评论(0) 推荐(0) 编辑
摘要:class Solution(object): def get_f_l(self,s_length,s,list_all,last_d): max_l=0 first_d=0 last_d=0 for i in range(len(list_all)): if((i+1)==len(list_al... 阅读全文
posted @ 2019-03-07 23:48 anobscureretreat 阅读(97) 评论(0) 推荐(0) 编辑
摘要:class Solution(object): def reverse(self, x): """ :type x: int :rtype: int """ p=abs(x) rev=int(str(p)[::-1]) if(x(pow(2,31)-1)): ... 阅读全文
posted @ 2019-03-07 13:37 anobscureretreat 阅读(192) 评论(0) 推荐(0) 编辑
摘要:class Solution(object): def hb(self,list1,list2): result = [] while list1 and list2: if list1[0] < list2[0]: result.append(list1[0]) ... 阅读全文
posted @ 2019-03-04 11:46 anobscureretreat 阅读(125) 评论(0) 推荐(0) 编辑
摘要:class Solution(object): def addTwoNumbers(self, l1, l2): l3 = ListNode(0) current = l3 carry = 0 while l1 or l2: # 1,1 | None,1 | 1,None # Pad 0 if N... 阅读全文
posted @ 2019-03-04 10:41 anobscureretreat 阅读(125) 评论(0) 推荐(0) 编辑
摘要:class Solution(object): def twoSum(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ dictionary = dict() ... 阅读全文
posted @ 2019-03-04 10:39 anobscureretreat 阅读(147) 评论(0) 推荐(0) 编辑
摘要:class Solution(object): def lengthOfLongestSubstring(self, s): d = "" f = "" for i in range(len(s)): if s[i] not in f: f += s[i] ... 阅读全文
posted @ 2019-03-04 10:32 anobscureretreat 阅读(138) 评论(0) 推荐(0) 编辑