#leetCode

leetcode 13 -> Roman to Integer

 classSolution(object):defromanToInt(self,s):""":types:str:rtype:int"""lista={'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000}Value_sum=0last_Value=0for...
代码星球 ·2020-08-09

leetcode 12 -> Integer to Roman

 classSolution(object):defintToRoman(self,num):""":typenum:int:rtype:str"""ifnum==0:return""ifnum>=1000:return"M"+self.intToRoman(num-1000)elifnum>=9...
代码星球 ·2020-08-09

leetcode 9 -> Palindrome Number

 classSolution(object):defisPalindrome(self,x):""":typex:int:rtype:bool"""s=str(x)if(s==s[::-1]):returnTrueelse:returnFalse ...
代码星球 ·2020-08-09

leetcode 5-> Longest Palindromic Substring

 classSolution(object):defget_f_l(self,s_length,s,list_all,last_d):max_l=0first_d=0last_d=0foriinrange(len(list_all)):if((i+1)==len(list_all)):breakforjinr...

leetcode 7-> Reverse Integer(32-bit signed integer)

 classSolution(object):defreverse(self,x):""":typex:int:rtype:int"""p=abs(x)rev=int(str(p)[::-1])if(x<0):if((-rev)<pow(-2,31)):return0else:return-(re...

leetcode 4-> Median of Two Sorted Arrays

 classSolution(object):defhb(self,list1,list2):result=[]whilelist1andlist2:iflist1[0]<list2[0]:result.append(list1[0])dellist1[0]else:result.append(list...

leetcode 2-> Add Two Numbers

 classSolution(object):defaddTwoNumbers(self,l1,l2):l3=ListNode(0)current=l3carry=0whilel1orl2:#1,1|None,1|1,None#Pad0ifNoneifl1isNone:l1v=0else:l1v=l1.val...
代码星球 ·2020-08-09

leetcode 1 -> Two Sum

 classSolution(object):deftwoSum(self,nums,target):""":typenums:List[int]:typetarget:int:rtype:List[int]"""dictionary=dict()pos=0whilepos<len(nums):if(t...
代码星球 ·2020-08-09

leetcode 3-> Longest Substring Without Repeating Characters

 classSolution(object):deflengthOfLongestSubstring(self,s):d=""f=""foriinrange(len(s)):ifs[i]notinf:f+=s[i]else:iflen(d)<len(f):d=ff=f[f.index(s[i])+1::...

【leetCode】4. Median of Two Sorted Arrays

Therearetwosortedarrays nums1 and nums2 ofsizemandnrespectively.Findthemedianofthetwosortedarrays.TheoverallruntimecomplexityshouldbeO(log(m...

【LeetCode-面试算法经典-Java实现】【所有题目目录索引】

转自:https://blog.csdn.net/DERRANTCM/article/details/46905087 ...

LeetCode算法题详解之两个数组的交集

题目背景: 这个与我们高中时期学习的交集是一样的,顺便复习一下相关的数学知识有助于更好的理解。交集的定义: 对于两个集合A和B,定义A和B的交集为C,其中C={x|x属于A且X属于B},记作A∩B。如图所示:  解题思路一:publicint[]intersect(int...

LeetCode976 三角形的最大周长(Java排序简单应用-防自闭题)

题目:给定由一些正数(代表长度)组成的数组A,返回由其中三个长度组成的、面积不为零的三角形的最大周长。如果不能形成任何面积不为零的三角形,返回 0。 来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/largest-perimeter-triang...

LeetCode 922 按奇偶排序数组(记录一下原地排序方法)

题目:给定一个非负整数数组A,A中一半整数是奇数,一半整数是偶数。对数组进行排序,以便当A[i]为奇数时,i也是奇数;当A[i]为偶数时,i也是偶数。你可以返回任何满足上述条件的数组作为答案。 示例:输入:[4,2,5,7]输出:[4,5,2,7]解释:[4,7,2,5],[2,5,4,7],[2,7,4,5...

LeetCode242 有效的字母异位词(Java字符数组排序&自定义排序记录)

题目:给定两个字符串s和t,编写一个函数来判断t是否是s的字母异位词。 示例1:输入:s="anagram",t="nagaram"输出:true 来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/valid-anagram思路:将字符串中的字母按...
首页上一页...2627282930...下一页尾页