- 博客(25)
- 资源 (3)
- 收藏
- 关注
原创 ❤leetcode,python2❤给定一个二叉树,检查它是否是镜像对称的。
# Definition for a binary tree node.# class TreeNode(object):# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution(object): d...
2018-06-22 17:43:22 691
原创 ❤leetcode,python2❤二叉树的最大深度
class Solution(object): def maxDepth(self, root): """ :type root: TreeNode :rtype: int """ if root == None: return 0 else: r...
2018-06-12 11:49:19 256
原创 ❤leetcode,python2❤给定一个链表,判断链表中是否有环。
class Solution(object): def hasCycle(self, head): """ :type head: ListNode :rtype: bool """ if head == None: return False try: ...
2018-06-12 11:48:37 403
原创 ❤leetcode,python2❤请判断一个链表是否为回文链表。
class Solution(object): def isPalindrome(self, head): """ :type head: ListNode :rtype: bool """ list1 = [] list2 = [] if head == None: ...
2018-06-12 11:47:59 449
原创 ❤leetcode,python2❤将两个有序链表合并为一个新的有序链表并返回。新链表是通过拼接给定的两个链表的所有节点组成的。
class Solution(object): def mergeTwoLists(self, l1, l2): """ :type l1: ListNode :type l2: ListNode :rtype: ListNode """ if l1==None and l2==None: ...
2018-06-12 11:47:05 662
原创 ❤leetcode,python2❤反转链表
class Solution(object): def reverseList(self, head): """ :type head: ListNode :rtype: ListNode """ p = head q = None while p: c ...
2018-06-11 17:49:43 256
原创 ❤leetcode,python2❤给定一个链表,删除链表的倒数第 n 个节点,并且返回链表的头结点。
class Solution(object): def removeNthFromEnd(self, head, n): """ :type head: ListNode :type n: int :rtype: ListNode """ dummy = ListNode(-1) ...
2018-06-11 17:49:18 414
原创 ❤leetcode,python2❤请编写一个函数,使其可以删除某个链表中给定的(非末尾)节点,你将只被给定要求被删除的节点。
class Solution(object): def deleteNode(self, node): """ :type node: ListNode :rtype: void Do not return anything, modify node in-place instead. """ node.val..
2018-06-11 17:48:42 858
原创 ❤leetcode,python2❤编写一个函数来查找字符串数组中的最长公共前缀。 如果不存在公共前缀,返回空字符串 “”。
class Solution(object): def longestCommonPrefix(self, strs): """ :type strs: List[str] :rtype: str """ rstr = '' if strs == []: return r...
2018-06-11 17:48:13 1679
原创 ❤leetcode,python2❤报数序列是指一个整数序列,按照其中的整数的顺序进行报数,得到下一个数
class Solution(object): def countAndSay(self, n): """ :type n: int :rtype: str """ old = '1' for i in range(n-1): num = 1 va...
2018-06-11 17:47:39 909
原创 ❤leetcode,python2❤给定一个字符串,验证它是否是回文串,只考虑字母和数字字符,可以忽略字母的大小写。
class Solution(object): def isPalindrome(self, s): """ :type s: str :rtype: bool """ s = filter(str.isalnum, str(s)).lower() if s == s[::-1]: ...
2018-06-11 17:47:09 1585
原创 ❤leetcode,python2❤有效的字母异位词
class Solution(object): def isAnagram(self, s, t): """ :type s: str :type t: str :rtype: bool """ if len(s) != len(t): return False ...
2018-06-11 17:46:38 177 1
原创 ❤leetcode,python2❤给定一个字符串,找到它的第一个不重复的字符,并返回它的索引。如果不存在,则返回 -1。
class Solution(object): def firstUniqChar(self, s): """ :type s: str :rtype: int """ for i in range(len(s)): if s[i] not in s[i+1:] and s[i] not...
2018-06-11 17:46:12 3555
原创 ❤leetcode,python2❤颠倒整数
class Solution(object): def reverse(self, x): """ :type x: int :rtype: int """ if str(x)[0] == '-': num = int('-'+str(x)[1:][::-1]) els...
2018-06-11 17:43:46 251
原创 ❤leetcode,python2❤请编写一个函数,其功能是将输入的字符串反转过来。
class Solution(object): def reverseString(self, s): """ :type s: str :rtype: str """ return str(s)[::-1]
2018-06-11 17:42:58 2720
原创 ❤leetcode,python2❤给定一个 n × n 的二维矩阵表示一个图像。 将图像顺时针旋转 90 度。
class Solution(object): def rotate(self, matrix): """ :type matrix: List[List[int]] :rtype: void Do not return anything, modify matrix in-place instead. """ ..
2018-06-09 21:33:04 2494
原创 ❤leetcode,python2❤判断一个 9x9 的数独是否有效。只需要根据以下规则,验证已经填入的数字是否有效即可
class Solution(object): def isValidSudoku(self, board): """ :type board: List[List[str]] :rtype: bool """ for i in xrange(9): hang = board[i] ..
2018-06-09 21:32:44 1936
原创 ❤leetcode,python2❤给定一个整数数组和一个目标值,找出数组中和为目标值的两个数。
class Solution(object): def twoSum(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ for i in xrange(len(nums))..
2018-06-09 21:32:21 1814 1
原创 ❤leetcode,python2❤给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺序
class Solution(object): def moveZeroes(self, nums): """ :type nums: List[int] :rtype: void Do not return anything, modify nums in-place instead. """ j=0 ..
2018-06-09 21:32:02 1864 1
原创 ❤leetcode,python2❤给定一个非负整数组成的非空数组,在该数的基础上加一,返回一个新的数组。
class Solution(object): def plusOne(self, digits): """ :type digits: List[int] :rtype: List[int] """ num = 1 for i in range(len(digits)): ..
2018-06-09 21:31:40 1274 2
原创 ❤leetcode,python2❤给定一个非空整数数组,除了某个元素只出现一次以外,其余每个元素均出现两次。找出那个只出现了一次的元素
class Solution(object): def singleNumber(self, nums): """ :type nums: List[int] :rtype: int """ nums.sort() for i in range(len(nums)): i..
2018-06-09 21:31:15 3465
原创 ❤leetcode,python2❤给定一个整数数组,判断是否存在重复元素。 如果任何值在数组中出现至少两次
class Solution(object): def containsDuplicate(self, nums): """ :type nums: List[int] :rtype: bool """ if len(set(nums)) == len(nums): return Fal...
2018-06-09 21:29:54 1231
原创 ❤leetcode,python2❤给定一个数组,将数组中的元素向右移动 k 个位置,其中 k 是非负数。
class Solution(object): def rotate(self, nums, k): """ :type nums: List[int] :type k: int :rtype: void Do not return anything, modify nums in-place instead. ...
2018-06-09 21:28:27 1309
原创 ❤leetcode,python2❤买卖股票的最佳时机 II
class Solution(object): def maxProfit(self, prices): “”” :type prices: List[int] :rtype: int “”” zong = 0 for i in range(len(prices)-1): ...
2018-06-09 21:28:00 132
原创 ❤leetcode,python2❤从排序数组中删除重复项
class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ for i in range(len(nums)): for j in range(i...
2018-06-09 21:23:58 216
uiautomatorviewer 可支持安卓android 8.0 - 12.0 的四个jar包
2022-03-30
htmltestrunner完美兼容python3,已解决print无法显示在html报告中的问题
2018-04-29
HTMLTestRunner汉化版
2017-01-09
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人