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 #267

Merged
merged 4 commits into from
Jan 4, 2024
Merged

Homework #267

merged 4 commits into from
Jan 4, 2024

Conversation

luopeis
Copy link

@luopeis luopeis commented Jan 3, 2024

No description provided.

@iphysresearch
Copy link
Owner

Good Job!!! @luopeis

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%

@iphysresearch
Copy link
Owner

@luopeis
把扩展作业也做一下吧哈!

Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@iphysresearch
Copy link
Owner

Good Job!!! @luopeis

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%

Copy link
Owner

Choose a reason for hiding this comment

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

Matplotlib数据可视化作业!

@iphysresearch
Copy link
Owner

iphysresearch commented Jan 3, 2024

@luopeis
看到Matplotlib作业了,别忘了把Python扩展作业做一下哦~~

@iphysresearch
Copy link
Owner

Good Job!!! @luopeis

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%

@iphysresearch
Copy link
Owner

@luopeis
还差个Python扩展作业5个题哈!

@luopeis
Copy link
Author

luopeis commented Jan 4, 2024

434 字符串中的单词数:

class Solution {
    public int countSegments(String s) {
        // 接受一个字符串参数s并返回一个整数值String[] str = s.split(" ");// 这一行将字符串s按照空格进行分割并将结果存储在一个字符串数组str中根据空格将字符串划分为多个单词并将这些单词存储在数组中int count = 0;
        for (String s1 : str) {
            if (!s1.equals("")) {
                count++;
            }
        } // for循环和if计数
        return count;
    }
}

1869那种连续子字符串更长

class Solution {
    public boolean checkZeroOnes(String s) {
        int l = s.length(); // 获取字符串s的长度
        int m = 0, resm = 0; // 记录连续的1的数量和最大连续1的数量
        int n = 0, resn = 0; // 记录连续的0的数量和最大连续0的数量
        
        for (int i = 0; i < l; i++) { // 遍历字符串s的每个字符
            if (s.charAt(i) == '1') { // 如果当前字符为'1'
                m++; // 1的计数增加
                resm = Math.max(m, resm); // 更新最大连续1的数量
                n = 0; // 0的计数重置为0
            } else { // 如果当前字符不为'1'即为'0'
                n++; // 0的计数增加
                m = 0; // 1的计数重置为0
                resn = Math.max(n, resn); // 更新最大连续0的数量
            }
        }
        
        return resm > resn ? true : false; // 比较最大连续1的数量和最大连续0的数量返回相应的布尔值
    }
}
  1. 检查二进制字符串字段
class Solution {
    public boolean checkOnesSegment(String s) {
        return !s.contains("01"); // 检查字符串s中是否包含"01"返回是否不包含的结果
    }
}
  1. 山脉数组的峰顶索引
class Solution {
    public int peakIndexInMountainArray(int[] arr) {
        for (int i = 1; i < arr.length - 1; i++) { // 遍历数组arr从索引1开始到倒数第二个索引
            if (arr[i] > arr[i + 1]) { // 如果当前元素大于下一个元素
                return i; // 返回当前索引作为山峰的峰值索引
            }
        }
        return -1; // 如果未找到山峰返回-1表示未找到
    }
}

162.寻找峰值

class Solution {
public:
    int findPeakElement(vector<int>& nums) {
        int len = nums.size(); // 获取数组nums的长度
        for (int i = 1; i < len - 1; i++) { // 遍历数组从索引1开始到倒数第二个索引
            if (nums[i] > nums[i - 1] && nums[i] > nums[i + 1]) { // 如果当前元素大于前一个元素且大于后一个元素
                return i; // 返回当前索引作为峰值索引
                break; // 结束循环
            }
        }
        if (nums[0] > nums[len - 1]) { // 如果第一个元素大于最后一个元素
            return 0; // 返回第一个元素的索引作为峰值索引
        }
        return len - 1; // 返回最后一个元素的索引作为峰值索引
    }

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.

@luopeis
完成Python基础+拓展作业,Matplotlib数据可视化作业!

@iphysresearch iphysresearch merged commit de1a33e into iphysresearch:homework Jan 4, 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