Skip to content

Commit

Permalink
homework
Browse files Browse the repository at this point in the history
  • Loading branch information
suiranruofeng committed Dec 20, 2023
1 parent b916e6b commit 349f118
Show file tree
Hide file tree
Showing 5 changed files with 1,876 additions and 0 deletions.
161 changes: 161 additions & 0 deletions 2023/homework/XuWeiZhang-UCAS/LeetcodeHW.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"434. Number of Segments in a String"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class Solution(object):\n",
" def countSegments(self, s):\n",
" \"\"\"\n",
" :type s: str\n",
" :rtype: int\n",
" \"\"\"\n",
" return len(s.split()) #运用内建的split()函数"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"852. Peak Index in a Mountain Array"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class Solution(object):\n",
" def peakIndexInMountainArray(self, arr):\n",
" \"\"\"\n",
" :type arr: List[int]\n",
" :rtype: int\n",
" \"\"\"\n",
" # 遍历,对于每一个元素,判断它是否大于它前面和后面的元素,如果是,则返回当前索引\n",
" for i in range(1, len(arr)-1):\n",
" if arr[i] > arr[i-1] and arr[i] > arr[i+1]:\n",
" return i"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"1784. Check if Binary String Has at Most One Segment of Ones\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class Solution(object):\n",
" def checkZeroOnes(self, s):\n",
" \"\"\"\n",
" :type s: str\n",
" :rtype: bool\n",
" \"\"\"\n",
" x = s.split('0')\n",
" y = s.split('1') # 用split函数把字符串的各个独立部分分割\n",
"\n",
" mx0,mx1 = 0,0 #初始化0和1的长度参数\n",
"\n",
" # 遍历两组字符串的组,用max函数获得最长的字符串\n",
" for i in x:\n",
" mx0 = max(mx0, len(i))\n",
" for i in y:\n",
" mx1 = max(mx1, len(i))\n",
" return (mx0 > mx1)# 比较长度得到结果"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"1869. Longer Contiguous Segments of Ones than Zeros"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class Solution(object):\n",
" def checkOnesSegment(self, s):\n",
" \"\"\"\n",
" :type s: str\n",
" :rtype: bool\n",
" \"\"\"\n",
" count = 0 # 计数初始化\n",
" x = s.split(\"0\") # 以0分割字符串\n",
" # 遍历分割后的数组,计数\n",
" for i in x:\n",
" if i:\n",
" count += 1\n",
" return count == 1 # 判断个数"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"162. Find Peak Element"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"class Solution(object):\n",
" def findPeakElement(self, nums):\n",
" \"\"\"\n",
" :type nums: List[int]\n",
" :rtype: int\n",
" \"\"\"\n",
" max = nums[0]\n",
" peak = 0 # 初始化参数\n",
" for i in range(len(nums)): # 循环判断最大值并获得此时序号\n",
" if nums[i] > max:\n",
" max = nums[i]\n",
" peak = i\n",
"\n",
" return peak # 返回序号"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "ictp-ap",
"language": "python",
"name": "ictp-ap"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
1,585 changes: 1,585 additions & 0 deletions 2023/homework/XuWeiZhang-UCAS/homework-matplotlib_seaborn.ipynb

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions 2023/homework/XuWeiZhang-UCAS/numpy_submit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
C
D
B
E
C
C
E
C
C
E
12 changes: 12 additions & 0 deletions 2023/homework/XuWeiZhang-UCAS/pandas_submit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
B
D
C
A
B
D
A
C
C
B
B
B
108 changes: 108 additions & 0 deletions 2023/homework/XuWeiZhang-UCAS/python_submit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
C
B
C
C
C
A
A
B
B
B
B
C
A
D
A
A
A
C
D
B
A
D
C
A
D
B
C
B
A
C
C
C
B
C
D
B
A
C
D
A
B
A
C
A
C
D
B
A
B
A
A
A
B
D
D
B
A
D
B
C
B
B
A
D
A
D
A
B
A
A
D
B
C
A
C
C
B
B
C
A
B
A
C
B
A
C
C
B
B
B
A
C
A
B
B
A
A
A
C
C
A
B
B
A
A
B
A
A

0 comments on commit 349f118

Please sign in to comment.