- 博客(17)
- 收藏
- 关注
原创 #task17 最长回文字符串
#leetcode题class Solution(object): def longestPalindrome(self, s): n=len(s) s1='' for i in range(n-1,-1,-1): s1+=s[i] #建立一个和原字符串对称的字符串 max1='' ...
2020-03-17 13:34:47 65
原创 #Task16 无重复字符串的最长子串
#leetcode题:class Solution: def lengthOfLongestSubstring(self, s: str) -> int: str1='' max1=0 for x in range(0,len(s)): str1='' lp=0 for i in range...
2020-03-16 19:45:43 62
原创 #Task15 有效的括号
#leetcode题class Solution: def isValid(self, s: str) -> bool: while '{}' in s or '()' in s or '[]' in s: s = s.replace('{}', '') s = s.replace('[]', '') ...
2020-03-15 13:57:39 72
原创 #task14 最长公共前缀
#leetcode Q:class Solution(object): def longestCommonPrefix(self, strs): """ :type strs: List[str] :rtype: str """ str1='' if not strs:# Check if ...
2020-03-14 11:05:02 80
原创 Task13罗马数字转整数
#leetcode题class Solution(object): def romanToInt(self, s): """ :type s: str :rtype: int """ sum1=0 list1={'I':1,'V':5,'X':10,'L':50,'C':100,...
2020-03-13 08:58:53 89
原创 #Task12:合并K个排序链表
#leetcode题class Solution(object): def mergeKLists(self, lists): """ :type lists: List[ListNode] :rtype: ListNode """ list1=[] for each in lists: ...
2020-03-12 17:31:30 43
原创 #task11删除链表中倒数第n个节点
#leetcode题class Solution: def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode: i=0 p=ListNode(0) p.next=head q=head while(q): i+...
2020-03-11 19:52:58 73
原创 #Task10两数相加
#leetcode题class Solution: def addTwoNumbers(self, l1: ListNode, l2: ListNode) -> ListNode: x=0 l3=ListNode(0)#定义新的链表 t=l3 while(l1 or l2 or x!=0): #在L1...
2020-03-10 15:37:14 80
原创 #Task 09 环形链表
#leetcode题class Solution: def hasCycle(self, head: ListNode) -> bool: p=head if not p or not p.next or not p.next.next : return False while(p and p.next...
2020-03-09 17:18:12 68
原创 #task08删除排序列表中的重复元素
#leetcode题两种做法:1.递归class Solution: def deleteDuplicates(self,p: ListNode) -> ListNode: if not p or not p.next: return p p.next=self.deleteDuplicates(p.next) ...
2020-03-08 16:18:42 125
原创 #task07 合并两个有序链表
#leetcode题目class Solution: def mergeTwoLists(self, l1: ListNode, l2: ListNode) ListNode: if l1 is None and l2 is None: return None if ...
2020-03-07 22:39:23 62
原创 #task06 买股票的最佳时机3
#leetcode题目class Solution: def maxProfit(self, prices: List[int]) -> int: if prices==[]: return 0 a=-prices[0] b=-float('inf') c=-float('inf') ...
2020-03-06 21:10:14 102
原创 #最接近的三数之和
#leetcode题class Solution: def threeSumClosest(self, nums: List[int], target: int) -> int: nums.sort() list1=[] mins=nums[0]+nums[1]+nums[2]-target for i in ran...
2020-03-05 20:26:54 101
原创 #task04三数之和
class Solution: def threeSum(self, nums: List[int]) -> List[List[int]]: list1=[] nums.sort() for i in range(0,len(nums)-2): if nums[i]>0 : ...
2020-03-02 19:22:23 135
原创 #task 03 移除元素
#leetcode题class Solution(object): def removeElement(self, nums, val): """ :type nums: List[int] :type val: int :rtype: int """ for i in range(len(...
2020-03-02 19:10:55 81
原创 #task02 删除排序数组中的重复项
#leetcode题class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ for i i...
2020-03-01 21:35:08 96
原创 #task 01 两数之和
题:给定一个整数数组nums和一个目标值target,在该数组中找出和为目标值的那两个整数并返回他们的数组下标。class Solution(object): def twoSum(self, nums, target): """ :type nums: List[int] :type target...
2020-03-01 10:38:46 72
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人