leetcode
Initial-T
规格严格,功夫到家。做优秀的软件工程师,写漂亮的代码。
展开
-
python实现leetcode-第26题-删除排序数组中的重复项
class Solution: def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ i = 0 while i+1 < len(nums): if nums[i] ...原创 2019-01-17 21:33:49 · 311 阅读 · 0 评论 -
python实现leetcode-第3题-无重复字符的最长子串
class Solution: def lengthOfLongestSubstring(self, s: str) -> int: # 存储历史循环中最长的子串长度 max_len = 0 # 判断传入的字符串是否为空 if s is None or len(s) == 0: return m...原创 2019-03-06 20:40:30 · 183 阅读 · 0 评论 -
python实现leetcode-第2题-两数相加
题目:给出两个非空的链表用来表示两个非负的整数。其中,它们各自的位数是按照逆序的方式存储的,并且它们的每个节点只能存储一位数字。如果,我们将这两个数相加起来,则会返回一个新的链表来表示它们的和。您可以假设除了数字 0 之外,这两个数都不会以 0开头。示例:输入:(2 -> 4 -> 3) + (5 -> 6 -> 4)输出:7 ->...原创 2019-02-27 21:17:27 · 1750 阅读 · 0 评论 -
python实现leetcode-第28题-实现strStr()
class Solution: def strStr(self, haystack, needle): """ :type haystack: str :type needle: str :rtype: int """ if needle == "" or needle == haystack...原创 2019-01-30 14:35:13 · 368 阅读 · 0 评论 -
python实现leetcode-第21题-合并两个有序链表
1 链表结构 链表结构是由许多节点构成的,每个节点都包含两部分: 数据部分:保存该节点的实际数据。 地址部分:保存的是下一个节点的地址。链表的特点:结点在存储器中的位置是任意的,即逻辑上相邻的数 据元素在物理上不一定相邻访问时只能通过头指针进入链表,并通过每个结点的 指针域向后扫描其余结点,所以寻找第一个结点和最后一 个结点所花费的时间不等链表的优点:数据元素的个数可...原创 2019-01-16 22:48:40 · 326 阅读 · 0 评论 -
python实现leetcode-第20题-有效的括号
一开始,尝试通过列出所有错误情况求解:class Solution: def isValid(self, s): """ :type s: str :rtype: bool """ sl=sr=mr=ml=bl=br=snum=snum2=mnum=mnum2=bnum=bnum2=0 f...原创 2019-01-16 15:06:11 · 314 阅读 · 0 评论 -
python实现leetcode-第35题-搜索插入位置
class Solution: def searchInsert(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int """ n = 0 for i in range(len(...原创 2019-01-31 19:45:28 · 177 阅读 · 0 评论 -
python实现leetcode-第18题-最大公共前缀
class Solution: def longestCommonPrefix(self, strs): """ :type strs: List[str] :rtype: str """ costr = "" if strs == [] or strs ==[""]: ...原创 2019-01-15 16:39:44 · 109 阅读 · 0 评论 -
python实现leetcode-第13题-罗马数字转整数
class Solution: def romanToInt(self, s): """ :type s: str :rtype: int """ num1=num4=num5=num9=num10=num40=num50=num90=num100=num400=num500=num900=num1000=0...原创 2019-01-15 14:31:05 · 148 阅读 · 0 评论 -
python实现leetcode-第9题-回文数判断
class Solution: def isPalindrome(self, x): """ :type x: int :rtype: bool """ if x == 0: return True else: strX = str(x) ...原创 2019-01-14 21:38:15 · 220 阅读 · 0 评论 -
python实现leetcode-第7题-整数反转
import mathclass Solution: def reverse(self, x): """ :type x: int :rtype: int """ strX = str(x) if strX[0] != '-': strX1 = st...原创 2019-01-14 21:24:28 · 408 阅读 · 0 评论 -
python实现leetcode-第27题-移除元素
class Solution: def removeElement(self, nums, val): """ :type nums: List[int] :type val: int :rtype: int """ i = j = 0 while j < len(num...原创 2019-01-17 22:05:16 · 318 阅读 · 0 评论 -
leetcode最热100题——1-10
1 给定一个整数数组 nums和一个目标值 target,请你在该数组中找出和为目标值的那两个整数,并返回他们的数组下标。你可以假设每种输入只会对应一个答案。但是,你不能重复利用这个数组中同样的元素。 for i in range(len(nums)): for j in range(i+1,len(nums)): ...原创 2019-06-15 23:42:57 · 4802 阅读 · 0 评论