自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(65)
  • 收藏
  • 关注

原创 袜子成对

题目:代码:#!/bin/python3import mathimport osimport randomimport reimport sys# Complete the sockMerchant function below.def sockMerchant(n, ar): count = 0 ar.sort() ar.append('*') i = 0 while i<n: if ar[i]==ar[i+1]:

2021-01-31 14:19:51 165

原创 AA 制吃晚餐

题目:代码:#!/bin/python3import mathimport osimport randomimport reimport sys# Complete the bonAppetit function below.def bonAppetit(bill, k, b): result = 0 for i in range(len(bill)): if i == k: continue result

2021-01-31 13:12:11 160

原创 算闰年

题目:代码:#!/bin/python3import mathimport osimport randomimport reimport sys# Complete the dayOfProgrammer function below.def dayOfProgrammer(year): result = '' if year >= 1700 and year <=1917: if year % 4 == 0:

2021-01-31 12:08:52 105

原创 打破记录

题目:代码:#!/bin/python3import mathimport osimport randomimport reimport sys# Complete the breakingRecords function below.def breakingRecords(scores): highest_score_count = 0 lowest_score_count = 0 highest = scores[0] lowest = scor

2021-01-26 16:30:23 158 2

原创 袋鼠跳

题目:代码:#!/bin/python3import mathimport osimport randomimport reimport sys# Complete the kangaroo function below.def kangaroo(x1, v1, x2, v2): if v2 - v1 == 0 and x1 != x2: return 'NO' if (x1-x2)%(v2-v1) == 0 and (x1-x2)*(v2-v1)

2021-01-26 13:36:01 157 2

原创 Leetcode 1: Two Sum

题目:python3代码:class Solution: def twoSum(self, nums: List[int], target: int) -> List[int]: nums = [(num, idx) for idx, num in enumerate(nums)] nums.sort(key=lambda x: x[0]) left, right = 0, len(nums) - 1 while left

2021-01-18 17:33:59 115

原创 Leetcode 50: Pow(x, n) - 超简洁

题目:python3代码:简单版:class Solution: def myPow(self, x: float, n: int) -> float: return x ** n递归版:class Solution: def myPow(self, x: float, n: int) -> float: if n == 0: return 1 if n < 0:

2021-01-18 12:22:45 106

原创 Leetcode 145 - Binary Tree Postorder Traversal

题目:python3代码:# Definition for a binary tree node.# class TreeNode:# def __init__(self, val=0, left=None, right=None):# self.val = val# self.left = left# self.right = rightclass Solution: def postorderTraversal(self,

2021-01-18 09:16:14 131

原创 RegEx (34) - 练习题 (四)

这道题考虑点比较多,比如逗号, 字母e.使用这些知识点来做练习如果觉得不错,就点赞和关注和留言吧~谢谢~

2021-01-18 08:13:44 146

原创 RegEx (33) - 练习题 (三)

要用到的表达方式:如果觉得不错,就点赞或者关注或者留言~谢谢~

2021-01-18 06:38:52 169

原创 RegEx (32) 练习题 (二)

如果觉得不错,就点赞或者关注或者留言吧~谢谢~

2021-01-18 05:25:27 168

原创 RegEx (31) 练习题 (一)

如果觉得不错,就点赞或者关注或者留言~谢谢~

2021-01-18 05:08:01 216

原创 Leetcode 112: Path Sum

题目:python3 代码:# Definition for a binary tree node.# class TreeNode:# def __init__(self, val=0, left=None, right=None):# self.val = val# self.left = left# self.right = rightclass Solution: def hasPathSum(self, root:

2021-01-15 11:49:21 531 13

原创 Leetcode 110: Balanced Binary Tree

题目:python3代码:# Definition for a binary tree node.# class TreeNode:# def __init__(self, val=0, left=None, right=None):# self.val = val# self.left = left# self.right = rightclass Solution: def isBalanced(self, root:

2021-01-15 10:18:15 242 14

原创 Leetcode 100: Same Tree

题目:python3代码:# Definition for a binary tree node.# class TreeNode:# def __init__(self, val=0, left=None, right=None):# self.val = val# self.left = left# self.right = rightclass Solution: def isSameTree(self, p: Tree

2021-01-14 14:12:09 179

原创 Leetcode 66: Plus One - 使用insert()方法

题目:python代码:class Solution: def plusOne(self, digits: List[int]) -> List[int]: i = len(digits)-1 digits[i] += 1 while digits[i]==10: digits[i] = 0 if i==0: digits.insert(0,1)

2021-01-13 11:02:42 142

原创 leetcode 53: Maximum Subarray

题目:python 代码:class Solution: def maxSubArray(self, nums: List[int]) -> int: if (len(nums) == 1): return nums[0] result = [] result.append(nums[0]) for i in range(1,len(nums)): result.append(

2021-01-12 16:21:23 153

原创 Leetcode: 35 - Search Insert Position

题目:用python3来写代码:class Solution: def searchInsert(self, nums: List[int], target: int) -> int: if len(nums) == 0: return 0 for i in range(len(nums)): if nums[i] < target and i == len(nums)-1: # The last o

2021-01-11 17:15:50 170 2

原创 Leetcode 28: Implement strStr()

题目:python3代码:class Solution: def strStr(self, haystack: str, needle: str) -> int: if (len(haystack) == 0 and len(needle) == 0) or (len(haystack) != 0 and len(needle) == 0): return 0 if len(haystack) < len(needle):

2021-01-11 15:28:42 126

原创 Leetcode (21) - Merge Two Sorted Lists

题目:python 代码:# Definition for singly-linked list.#class ListNode:# def __init__(self, val=0, next=None):# self.val = val# self.next = nextclass Solution: def mergeTwoLists(self, l1: ListNode, l2: ListNode) -> ListNode:

2021-01-11 10:28:28 112

原创 Leetcode 20: Valid Parentheses

题目:python code:class Solution: def isValid(self, s: str) -> bool: stack = [] for i in range(len(s)): character = s[i] if character != '(' and character != "{" and character != '[' and character != ")" and

2021-01-09 12:55:41 135

原创 Leetcode 9: Palindrome Number

题目:python 代码:class Solution: def isPalindrome(self, x: int) -> bool: x_str = str(x) x_rev = x_str[::-1] if x_str == x_rev: return True else: return False代码中使用的[::-1] 是用来reverse a String. T

2021-01-09 09:27:30 108

原创 Leetcode 7 : Reverse Integer - python版本

题目:Given a 32-bit signed integer, reverse digits of an integer.python代码:class Solution: def reverse(self, x: int) -> int: Res = 0 flag = 1 if x<0: x = abs(x) flag = -1 while x != 0:

2021-01-09 00:40:58 159

原创 RegEx (30) - 分别 ? () * +

使用python来做正则表达式:import retxt = "ii i iii"x = re.findall("(i)?", txt)print('(i)? 结果:',x)if x: print("Yes, there is at least one match!")else: print("No match")y = re.findall('i?', txt)print('i? 结果:',y)z = re.findall('i*', txt)print('i* 结果

2021-01-08 09:52:52 103

原创 RegEx (29) - 查找特殊字符

使用python来做正则表达式:import retxt = "+ - * / % ?"#Check if the string has any + characters:x = re.findall("[+]", txt)print('找x的结果:',x)if x: print("Yes, there is at least one match!")else: print("No match")y = re.findall("[?]", txt)print('找y的结果:

2021-01-08 00:10:39 226

原创 RegEx (28) - 使用[a-zA-Z]

使用python来做正则表达式:import retxt = "sdf DRE 2423 sdf"#Check if the string has any characters from a to z lower case, and A to Z upper case:x = re.findall("[a-zA-Z]", txt)print(x)if x: print("Yes, there is at least one match!")else: print("No matc

2021-01-08 00:10:18 277

原创 RegEx (27) - 使用[][][] 来找范围内的三位数

使用python来表示正则表达式:import retxt = "2343 33 089 2 sdf"#Check if the string has any three-digit numbers, from 000 to 199:x = re.findall("[0-1][0-9][0-9]", txt)print('numbers from 000 to 199 结果: ',x)if x: print("Yes, there is at least one match!")el

2021-01-08 00:09:58 139

原创 RegEx (26) - 使用[ ][ ] 来找在范围内的两位数

使用python来做正则表达式:import retxt = "2343 33 89 2 sdf"#Check if the string has any two-digit numbers, from 00 to 59:x = re.findall("[0-5][0-9]", txt)print('numbers from 00 to 59 结果: ',x)if x: print("Yes, there is at least one match!")else: print("

2021-01-08 00:09:26 191

原创 RegEx (25) -使用 [ ] 在某一范围来找数字

使用python来做正则表达式:import retxt = "0000 234324 2423 swer"#Check if the string has any digits:x = re.findall("[0-9]", txt)print(x)if x: print("Yes, there is at least one match!")else: print("No match")字符[0-9]: Returns a match for any digit betw

2021-01-08 00:06:47 158

原创 RegEx (24) - 使用[ ] 来检查string中有没有数字

使用python来做正则表达式:import retxt = "23n sdf 2432 42 sffw"#Check if the string has any 0, 1, 2, or 3 digits:x = re.findall("[0123]", txt)print(x)if x: print("Yes, there is at least one match!")else: print("No match")字符[0123]: Returns a match whe

2021-01-08 00:06:26 167

原创 RegEx (23) - 使用字符[^ ] 来寻找除了括号里的其他字符

使用python来做正则表达式:import retxt = "werew asdfs IIHHHLL 234"#Check if the string has other characters than a, r, or n:x = re.findall("[^arn]", txt)print(x)if x: print("Yes, there is at least one match!")else: print("No match")字符[^arn]: Returns

2021-01-08 00:06:03 173

原创 RegEx (22) - 使用字符[ ] 来寻找范围中的任何字符

使用python来做正则表达式:import retxt = "teg erwe df 23"#Check if the string has any characters between a and n:x = re.findall("[a-n]", txt)print('[a-n] 结果:',x)if x: print("Yes, there is at least one match for characters between a and n!")else: print(

2021-01-08 00:05:43 114

原创 RegEx (21) -使用 [ ] 字符,寻找string里的characters

使用python来做正则表达式:import retxt = "324 sd 4d ! ?"#Check if the string has any white space:x = re.findall("[ ]", txt)print(x)if x: print("Yes, there is at least one match!")else: print("No match")y = re.findall("[! ?]", txt)print(y)if y:

2021-01-08 00:05:15 105

原创 RegEx (20) -使用字符 \Z (大写)

使用python来做正则表达式:import retxt = "xcv xfr wfs"#Check if the string ends with "wfs":x = re.findall("wfs\Z", txt)print(x)if x: print("Yes, there is a match!")else: print("No match")txt_new = "234 2432 sw 543 sdfsd"y = re.findall("sdf\Z", txt_n

2021-01-07 09:50:34 153

原创 RegEx (19) - 使用字符 \W (大写字母)

使用python来做正则表达式:import retxt = "werew_wer wesdf 23423 !!! ?"#Return a match at every word character (characters from a to Z, digits from 0-9, and the underscore _ character):x = re.findall("\w", txt)print('使用小写字母:',x)if x: print("Yes, there is a

2021-01-07 09:26:47 448

原创 RegEx (18) - 使用字符 \w (小写字母)

使用python来做正则表达式:import retxt = "werew_wer wesdf 23423 !!!"#Return a match at every word character (characters from a to Z, digits from 0-9, and the underscore _ character):x = re.findall("\w", txt)print(x)if x: print("Yes, there is at least one

2021-01-07 09:21:33 395

原创 RegEx (17) - 使用字符 \S

使用python来做正则表达式:import retxt = "wer wer xfs wer"#Return a match at every NON white-space character:x = re.findall("\S", txt)print('使用大写字母\S结果:',x)if x: print("Yes, there is at least one match!")else: print("No match")txt_new = 'wer wer xfs

2021-01-07 09:15:56 370

原创 RegEx(16) - 使用字符 \s 找出空格位置

使用python来做正则表达式:import retxt = "sdf wer fsdf wer"#Return a match at every white-space character:x = re.findall("\s", txt)print('x 结果:',x)if x: print("Yes, there is at least one white-space!")else: print("No match")txt_new = '23423423sfsd234

2021-01-07 07:05:34 258

原创 RegEx (15) - 使用字符 \D 不包含数字

使用python来做正则表达式:import retxt = "wer DE ase 12"#Return a match at every no-digit character:x = re.findall("\D", txt)print('x 的结果:',x)if x: print("Yes, there is at least one match no-digit character!")else: print("No match")txt_new = '23 234

2021-01-07 06:57:59 361

原创 RegEx (14) - 使用字符 \d 包含数字

使用python来做正则表达式:import retxt = "12 324 rain"#Check if the string contains any digits (numbers from 0-9):x = re.findall("\d", txt)print('x 结果: ',x)if x: print("Yes, there is at least one match!")else: print("No match")txt_new = 'wer asdfw re

2021-01-07 06:38:38 228

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除