Skip to content
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

Merged
merged 7 commits into from
Jan 2, 2024
Merged

Homework #240

merged 7 commits into from
Jan 2, 2024

Conversation

Pdirac52
Copy link

try python, numpy and pandas homework

@iphysresearch
Copy link
Owner

Good Job!!! @Pdirac52

@iphysresearch
Copy link
Owner

Good Job!!! @Pdirac52

@Pdirac52
你需要update branch 一下哈! #137 (comment)

@iphysresearch
Copy link
Owner

Good Job!!! @Pdirac52

Python homework:

  • Total questions: 108
  • Correct answers: 1
  • Score: 0%

Numpy homework:

  • Total questions: 10
  • Correct answers: 10
  • Score: 100.00%

Pandas homework:

  • Total questions: 12
  • Correct answers: 12
  • Score: 100.00%

显示只对了一个,重新提交
@iphysresearch
Copy link
Owner

Good Job!!! @Pdirac52

Python homework:

  • Total questions: 108
  • Correct answers: 0
  • Score: 0%

Numpy homework:

  • Total questions: 10
  • Correct answers: 10
  • Score: 100.00%

Pandas homework:

  • Total questions: 12
  • Correct answers: 12
  • Score: 100.00%

@iphysresearch
Copy link
Owner

Good Job!!! @Pdirac52

Python homework:

  • Total questions: 108
  • Correct answers: 108
  • Score: 100.00%

Numpy homework:

  • Total questions: 10
  • Correct answers: 10
  • Score: 100.00%

Pandas homework:

  • Total questions: 12
  • Correct answers: 12
  • Score: 100.00%

@Pdirac52 Pdirac52 closed this Dec 30, 2023
@Pdirac52 Pdirac52 reopened this Dec 30, 2023
@iphysresearch
Copy link
Owner

Good Job!!! @Pdirac52

Python homework:

  • Total questions: 108
  • Correct answers: 108
  • Score: 100.00%

Numpy homework:

  • Total questions: 10
  • Correct answers: 10
  • Score: 100.00%

Pandas homework:

  • Total questions: 12
  • Correct answers: 12
  • Score: 100.00%

@Pdirac52
Copy link
Author

王老师,我想提交一下python,numpy,pandas基础作业

Copy link
Owner

@iphysresearch iphysresearch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pdirac52
很好哈!把Python编程的扩展作业也做一下吧哈?

@iphysresearch
Copy link
Owner

Good Job!!! @Pdirac52

Python homework:

  • Total questions: 108
  • Correct answers: 108
  • Score: 100.00%

Numpy homework:

  • Total questions: 10
  • Correct answers: 10
  • Score: 100.00%

Pandas homework:

  • Total questions: 12
  • Correct answers: 12
  • Score: 100.00%

@Pdirac52
Copy link
Author

Pdirac52 commented Jan 2, 2024

王老师好,是这样在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.1869

class 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.1784

class Solution:
    def checkOnesSegment(self, s: str) -> bool:
        return '01' not in s #只需要保证01不在字符串中就行

No.852

class Solution:
    def peakIndexInMountainArray(self, arr: List[int]) -> int:
        #题目提示已经保证了是一个山脉数组。即我找到后一个小于前一个的地方为山顶
        for i in range(len(arr)):
            if arr[i]>arr[i+1]:
                return i
#但是感觉还可以更快,用二分法,不断的取中间值来判断应该会更快

No.162

class 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

@iphysresearch
Copy link
Owner

@Pdirac52
恭喜完成Python编程的基础作业和扩展作业!

@iphysresearch iphysresearch merged commit 2d2fab0 into iphysresearch:homework Jan 2, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants