-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Homework #240
Homework #240
Conversation
Good Job!!! @Pdirac52 |
@Pdirac52 |
Good Job!!! @Pdirac52Python homework:
Numpy homework:
Pandas homework:
|
显示只对了一个,重新提交
Good Job!!! @Pdirac52Python homework:
Numpy homework:
Pandas homework:
|
Good Job!!! @Pdirac52Python homework:
Numpy homework:
Pandas homework:
|
Good Job!!! @Pdirac52Python homework:
Numpy homework:
Pandas homework:
|
王老师,我想提交一下python,numpy,pandas基础作业 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Pdirac52
很好哈!把Python编程的扩展作业也做一下吧哈?
Good Job!!! @Pdirac52Python homework:
Numpy homework:
Pandas homework:
|
王老师好,是这样在comment中提交leetcode作业对么 Leetcode:No.434:class Solution:
def countSegments(self, s):
segment_count = 0 #先定义初始计数为0
for i in range(len(s)): #做循环,遍历该字符串每一个字符
if (i == 0 or s[i - 1] == ' ') and s[i] != ' ':#当i-1是空格,且i不是空格时,认为i是一个单词的开头
segment_count += 1 #因此单词数加一
return segment_count No.1869class Solution:
def checkZeroOnes(self, s: str) -> bool:
# 初始化变量
max0=0
max1=0
length0=0
length1=0
# 遍历字符串
for i in s:
if i=='1': #判断此时是不是1
length1 +=1 #如果是则给加上1,就能数出目前的1子串有多长
max0=max(length0,max0) #同时给上一个0的最长子串存档并且清零临时子串
length0=0
elif i=='0': #对于0的做法同理
length0 +=1
max1=max(length1,max1)
length1=0
max1=max(length1,max1) #最后得又赋值一遍,因为如果子串全是1,则不会进入elif的0,则没有给1存入最长子串
max0=max(length0,max0) #所以需要又存一次
return max1>max0 No.1784class Solution:
def checkOnesSegment(self, s: str) -> bool:
return '01' not in s #只需要保证01不在字符串中就行 No.852class Solution:
def peakIndexInMountainArray(self, arr: List[int]) -> int:
#题目提示已经保证了是一个山脉数组。即我找到后一个小于前一个的地方为山顶
for i in range(len(arr)):
if arr[i]>arr[i+1]:
return i
#但是感觉还可以更快,用二分法,不断的取中间值来判断应该会更快 No.162class Solution:
def findPeakElement(self, nums: List[int]) -> int:
#思路,不断的取中间值来寻找
#先找到中间值,然后判断是否是峰值
#如果是则已经找到
#如果不是,则看中间值两边谁大,然后往大的那边去靠近
#因为题目给的列表一定是两边小的
n=len(nums)
def get(i): #方便处理边界,我们让边界是负无穷,不影响数组整体的山峰
if i==-1 or i==n:
return float('-inf')
return nums[i]
#初始化我们左右取值
left,right,ans =0,n-1,-1
while left<=right:
#保证左边小于等于右边
mid =(left+right)//2
#然后去判断中间值是否是山峰
if get(mid-1)<get(mid)>get(mid+1):
ans=mid
break
#如果不是山峰,则左右往是山峰的那一次靠近
if get(mid)<get(mid+1):
left=mid+1
else:
right=mid-1
return ans |
@Pdirac52 |
try python, numpy and pandas homework