- 博客(67)
- 收藏
- 关注
原创 Python, LeetCode, 6. Z字形变换
class Solution: def convert(self, s, numRows): """ :type s: str :type numRows: int :rtype: str """ N = len(s) res = '' if numRows ==...
2018-06-08 16:57:46
842
原创 Python, LeetCode, 8. 字符串转整数 (atoi)
class Solution: def myAtoi(self, str): """ :type str: str :rtype: int """ s = str.strip() syb = 1 ptr = 0 res = 0 if len(s) ...
2018-06-08 12:02:37
892
原创 Python, LeetCode, 4. 两个排序数组的中位数
class Solution: def findMedianSortedArrays(self, nums1, nums2): """ :type nums1: List[int] :type nums2: List[int] :rtype: float """ nums = [] ...
2018-06-08 10:53:04
512
1
原创 Python, LeetCode, 14. 最长公共前缀
class Solution: def longestCommonPrefix(self, strs): """ :type strs: List[str] :rtype: str """ if len(strs) == 0: return '' tmp = strs[0...
2018-06-03 21:24:15
502
原创 Python, LeetCode, 13. 罗马数字转整数
class Solution: def romanToInt(self, s): """ :type s: str :rtype: int """ s_list = list(s) if len(s_list) == 0: return 0 res = 0...
2018-06-03 20:51:10
200
1
原创 Python, LeetCode, 50. Pow(x, n)
class Solution: def myPow(self, x, n): """ :type x: float :type n: int :rtype: float """ return x**n
2018-06-03 11:03:56
349
原创 Python, LeetCode, 412. Fizz Buzz
class Solution: def fizzBuzz(self, n): """ :type n: int :rtype: List[str] """ res = [] for i in range(1, n+1): if i%3 == 0: ...
2018-06-03 11:01:18
124
原创 Python, LeetCode, 290. 单词模式
class Solution: """ @param pattern: a string, denote pattern string @param str: a string, denote matching string @return: an boolean, denote whether the pattern string and the matching...
2018-05-18 10:24:42
354
原创 Python, LintCode, 391. 数飞机
"""Definition of Interval.class Interval(object): def __init__(self, start, end): self.start = start self.end = end"""class Solution: """ @param airplanes: An interval...
2018-05-17 22:43:47
304
原创 Python, LeetCode, 56. 合并区间
"""Definition of Interval.class Interval(object): def __init__(self, start, end): self.start = start self.end = end"""class Solution: """ @param intervals: interval li...
2018-05-17 20:08:56
868
1
原创 Python, LintCode, 372. Delete Node in a Linked List
"""Definition of ListNodeclass ListNode(object): def __init__(self, val, next=None): self.val = val self.next = next"""class Solution: """ @param: node: the node in ...
2018-05-17 11:31:41
142
原创 Python, LeetCode, 110. 平衡二叉树
"""Definition of TreeNode:class TreeNode: def __init__(self, val): self.val = val self.left, self.right = None, None"""class Solution: """ @param root: The root of bin...
2018-05-16 17:42:05
397
原创 Python, LintCode, 415. 有效回文串
class Solution: """ @param s: A string @return: Whether the string is a valid palindrome """ def isPalindrome(self, s): # write your code here if s == None: ...
2018-05-16 17:18:12
256
原创 Python, LeetCode, 28. 实现strStr()
class Solution: """ @param: source: source string to be scanned. @param: target: target string containing the sequence of characters to match @return: a index to the first occurrence o...
2018-05-16 15:34:28
280
原创 Python, LeetCode, 67. 二进制求和
class Solution: """ @param a: a number @param b: a number @return: the result """ def addBinary(self, a, b): # write your code here a = list(a) b = list...
2018-05-16 10:27:41
435
原创 Python, LintCode, 433. 岛屿的个数
class Solution: """ @param grid: a boolean 2D matrix @return: an integer """ def numIslands(self, grid): # write your code here if len(grid) == 0 or grid == None: ...
2018-05-13 11:45:21
948
原创 Python, LintCode, 488. 快乐数
class Solution: """ @param n: An integer @return: true if this is a happy number or false """ def isHappy(self, n): # write your code here while True: t...
2018-05-12 11:09:16
334
原创 Python, LeetCode, 88. 合并两个有序数组
class Solution: """ @param: A: sorted integer array A which has m elements, but size of A is m+n @param: m: An integer @param: B: sorted integer array B which has n elements @param...
2018-05-12 10:52:14
542
原创 Python, LeetCode, 26. 删除排序数组中的重复项
class Solution: """ @param: nums: An ineger array @return: An integer """ def removeDuplicates(self, nums): # write your code here i = 0 while i+1 < len(...
2018-05-12 10:21:04
265
原创 Python, LeetCode, 27. 移除元素
class Solution: """ @param: A: A list of integers @param: elem: An integer @return: The new length after remove """ def removeElement(self, A, elem): # write your code ...
2018-05-12 09:50:37
150
原创 Python, LintCode, 41. 最大子数组
class Solution: """ @param nums: A list of integers @return: A integer indicate the sum of max subarray """ def maxSubArray(self, nums): # write your code here if l...
2018-05-12 09:00:43
172
原创 Python, LintCode, 420. 报数
class Solution: """ @param n: the nth @return: the nth sequence """ def countAndSay(self, n): # write your code here if n == 1: return "1" if n ...
2018-05-11 21:56:15
217
原创 Python, LeetCode, 5. 最长回文子串
class Solution: """ @param s: input string @return: the longest palindromic substring """ def longestPalindrome(self, s): # write your code here res = "" if...
2018-05-10 22:48:29
363
原创 Python, LintCode, 627. 最长回文串
class Solution: """ @param s: a string which consists of lowercase or uppercase letters @return: the length of the longest palindromes that can be built """ def longestPalindrome(s...
2018-05-10 11:04:12
161
原创 Python, LeetCode, 9. 回文数
class Solution: """ @param num: a positive number @return: true if it's a palindrome or false """ def isPalindrome(self, num): # write your code here s = str(num) ...
2018-05-10 10:48:28
170
原创 Python, LeetCode, 21. 合并两个有序链表
"""Definition of ListNodeclass ListNode(object): def __init__(self, val, next=None): self.val = val self.next = next"""class Solution: """ @param l1: ListNode l1 is th...
2018-05-10 10:41:03
148
原创 Python, LintCode, 111. 爬楼梯
class Solution: """ @param n: An integer @return: An integer """ def climbStairs(self, n): # write your code here res = [0, 1, 2] if n <= 2: ...
2018-05-10 10:17:19
200
原创 Python, LeetCode, 66. 加一
class Solution: """ @param digits: a number represented as an array of digits @return: the result """ def plusOne(self, digits): # write your code here car = 1 ...
2018-05-10 10:04:35
213
原创 Python, LeetCode, 20. 有效的括号
class Solution: """ @param s: A string @return: whether the string is a valid parentheses """ def isValidParentheses(self, s): # write your code here N = len(s) ...
2018-05-09 19:36:00
219
原创 Python, LintCode, 46. Majority Element
class Solution: """ @param: nums: a list of integers @return: find a majority number """ def majorityNumber(self, nums): # write your code here if len(nums) == 0:...
2018-05-09 18:56:37
180
原创 Python, LintCode, 35. 翻转链表
"""Definition of ListNodeclass ListNode(object): def __init__(self, val, next=None): self.val = val self.next = next"""class Solution: """ @param head: n @return...
2018-05-09 18:45:40
220
原创 Python, LeetCode, 3. 无重复字符的最长子串
class Solution: """ @param: s: a string @return: an integer """ def lengthOfLongestSubstring(self, s): # write your code here res = 0 if s is None or len(s)...
2018-05-09 17:40:47
180
原创 Python, LintCode, 88. Lowest Common Ancestor of a Binary Tree
"""Definition of TreeNode:class TreeNode: def __init__(self, val): self.val = val self.left, self.right = None, None"""class Solution: """ @param: root: The root of t...
2018-05-03 21:10:51
164
原创 Python, LintCode, 453. 将二叉树拆成链表
"""Definition of TreeNode:class TreeNode: def __init__(self, val): self.val = val self.left, self.right = None, None"""class Solution: """ @param root: a TreeNode, the...
2018-05-03 11:58:06
192
原创 Python, LintCode, 480. 二叉树的所有路径
"""Definition of TreeNode:class TreeNode: def __init__(self, val): self.val = val self.left, self.right = None, None"""class Solution: """ @param root: the root of the...
2018-05-03 10:32:04
334
原创 Python, LintCode, 469. Same Tree
"""Definition of TreeNode:class TreeNode: def __init__(self, val): self.val = val self.left, self.right = None, None"""class Solution: """ @param a: the root of binary...
2018-05-03 09:36:27
164
原创 Python, LintCode, 175. 翻转二叉树
"""Definition of TreeNode:class TreeNode: def __init__(self, val): self.val = val self.left, self.right = None, None"""class Solution: """ @param root: a TreeNode, the...
2018-05-02 19:12:45
254
1
原创 Python, LintCode, 375. 克隆二叉树
"""Definition of TreeNode:class TreeNode: def __init__(self, val): self.val = val self.left, self.right = None, None"""class Solution: """ @param root: The root of bin...
2018-05-02 18:30:19
306
原创 Python, LintCode, 73. 前序遍历和中序遍历树构造二叉树
"""Definition of TreeNode:class TreeNode: def __init__(self, val): self.val = val self.left, self.right = None, None"""class Solution: """ @param inorder: A list of in...
2018-04-30 22:19:28
360
原创 Python, LintCode, 72. 中序遍历和后序遍历树构造二叉树
"""Definition of TreeNode:class TreeNode: def __init__(self, val): self.val = val self.left, self.right = None, None"""class Solution: """ @param inorder: A list of in...
2018-04-30 22:03:16
203
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人