bai-python-hwc 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bai_python_hwc/__init__.py +46 -0
- bai_python_hwc/answers/hwc101.py +38 -0
- bai_python_hwc/answers/hwc103.py +52 -0
- bai_python_hwc/answers/hwc104.py +45 -0
- bai_python_hwc/answers/hwc105.py +45 -0
- bai_python_hwc/answers/hwc106.py +56 -0
- bai_python_hwc/answers/hwc107.py +49 -0
- bai_python_hwc/answers/hwc108.py +45 -0
- bai_python_hwc/answers/hwc109.py +50 -0
- bai_python_hwc/answers/hwc110.py +42 -0
- bai_python_hwc/answers/hwc111.py +47 -0
- bai_python_hwc/answers/hwc112.py +42 -0
- bai_python_hwc/answers/hwc113.py +58 -0
- bai_python_hwc/answers/hwc114.py +58 -0
- bai_python_hwc/answers/hwc115.py +38 -0
- bai_python_hwc/answers/hwc116.py +44 -0
- bai_python_hwc/answers/hwc117.py +46 -0
- bai_python_hwc/answers/hwc118.py +47 -0
- bai_python_hwc/answers/hwc119.py +44 -0
- bai_python_hwc/answers/hwc120.py +41 -0
- bai_python_hwc/answers/hwc121.py +50 -0
- bai_python_hwc/answers/hwc122.py +54 -0
- bai_python_hwc/answers/hwc123.py +43 -0
- bai_python_hwc/answers/hwc124.py +41 -0
- bai_python_hwc/answers/hwc125.py +52 -0
- bai_python_hwc/answers/hwc126.py +40 -0
- bai_python_hwc/answers/hwc127.py +41 -0
- bai_python_hwc/answers/hwc128.py +39 -0
- bai_python_hwc/answers/hwc130.py +46 -0
- bai_python_hwc/answers/hwc131.py +46 -0
- bai_python_hwc/answers/hwc132.py +38 -0
- bai_python_hwc/answers/hwc133.py +61 -0
- bai_python_hwc/answers/hwc134.py +45 -0
- bai_python_hwc/answers/hwc135.py +49 -0
- bai_python_hwc/answers/hwc136.py +43 -0
- bai_python_hwc/answers/hwc201.py +47 -0
- bai_python_hwc/answers/hwc202.py +47 -0
- bai_python_hwc/answers/hwc203.py +48 -0
- bai_python_hwc/answers/hwc204.py +61 -0
- bai_python_hwc/answers/hwc205.py +56 -0
- bai_python_hwc/answers/hwc206.py +53 -0
- bai_python_hwc/answers/hwc207.py +43 -0
- bai_python_hwc/answers/hwc208.py +57 -0
- bai_python_hwc/answers/hwc209.py +42 -0
- bai_python_hwc/answers/hwc210.py +46 -0
- bai_python_hwc/answers/hwc211.py +62 -0
- bai_python_hwc/answers/hwc212.py +58 -0
- bai_python_hwc/answers/hwc213.py +54 -0
- bai_python_hwc/answers/hwc214.py +55 -0
- bai_python_hwc/answers/hwc215.py +53 -0
- bai_python_hwc/answers/hwc216.py +50 -0
- bai_python_hwc/answers/hwc217.py +38 -0
- bai_python_hwc/answers/hwc218.py +44 -0
- bai_python_hwc/answers/hwc219.py +49 -0
- bai_python_hwc/answers/hwc220.py +58 -0
- bai_python_hwc/answers/hwc221.py +49 -0
- bai_python_hwc/answers/hwc222.py +48 -0
- bai_python_hwc/answers/hwc223.py +39 -0
- bai_python_hwc/answers/hwc224.py +47 -0
- bai_python_hwc/answers/hwc225.py +50 -0
- bai_python_hwc/answers/hwc226.py +41 -0
- bai_python_hwc/answers/hwc227.py +40 -0
- bai_python_hwc/answers/hwc228.py +41 -0
- bai_python_hwc/answers/hwc229.py +51 -0
- bai_python_hwc/answers/hwc230.py +41 -0
- bai_python_hwc/answers/hwc231.py +39 -0
- bai_python_hwc/answers/hwc232.py +44 -0
- bai_python_hwc/answers/hwc233.py +49 -0
- bai_python_hwc/answers/hwc234.py +52 -0
- bai_python_hwc/answers/hwc235.py +45 -0
- bai_python_hwc/answers/hwc236.py +53 -0
- bai_python_hwc/answers/hwc237.py +56 -0
- bai_python_hwc/answers/hwc238.py +52 -0
- bai_python_hwc/answers/hwc239.py +60 -0
- bai_python_hwc/answers/hwc240.py +45 -0
- bai_python_hwc/answers/hwc241.py +48 -0
- bai_python_hwc/answers/hwc242.py +50 -0
- bai_python_hwc/answers/hwc243.py +61 -0
- bai_python_hwc/answers/hwc244.py +61 -0
- bai_python_hwc/answers/hwc245.py +47 -0
- bai_python_hwc/answers/hwc246.py +52 -0
- bai_python_hwc/answers/hwc247.py +76 -0
- bai_python_hwc/answers/hwc301.py +44 -0
- bai_python_hwc/answers/hwc302.py +53 -0
- bai_python_hwc/answers/hwc303.py +63 -0
- bai_python_hwc/answers/hwc304.py +56 -0
- bai_python_hwc/answers/hwc305.py +59 -0
- bai_python_hwc/answers/hwc306.py +60 -0
- bai_python_hwc/answers/hwc307.py +50 -0
- bai_python_hwc/answers/hwc308.py +59 -0
- bai_python_hwc/answers/hwc309.py +48 -0
- bai_python_hwc/answers/hwc310.py +38 -0
- bai_python_hwc/answers/hwc311.py +48 -0
- bai_python_hwc/answers/hwc312.py +49 -0
- bai_python_hwc/answers/hwc313.py +54 -0
- bai_python_hwc/answers/hwc314.py +49 -0
- bai_python_hwc/answers/hwc315.py +63 -0
- bai_python_hwc/answers/hwc316.py +65 -0
- bai_python_hwc/answers/hwc317.py +57 -0
- bai_python_hwc/answers/hwc318.py +55 -0
- bai_python_hwc/answers/hwc319.py +50 -0
- bai_python_hwc/answers/hwc320.py +84 -0
- bai_python_hwc/answers/hwc321.py +49 -0
- bai_python_hwc/answers/hwc322.py +49 -0
- bai_python_hwc/answers/hwc323.py +69 -0
- bai_python_hwc/answers/hwc324.py +66 -0
- bai_python_hwc/answers/hwc325.py +49 -0
- bai_python_hwc/answers/hwc326.py +53 -0
- bai_python_hwc/answers/hwc327.py +38 -0
- bai_python_hwc/answers/hwc328.py +50 -0
- bai_python_hwc/answers/hwc329.py +59 -0
- bai_python_hwc/answers/hwc330.py +45 -0
- bai_python_hwc/answers/hwc332.py +57 -0
- bai_python_hwc/answers/hwc401.py +50 -0
- bai_python_hwc/answers/hwc402.py +43 -0
- bai_python_hwc/answers/hwc403.py +73 -0
- bai_python_hwc/answers/hwc404.py +51 -0
- bai_python_hwc/answers/hwc405.py +62 -0
- bai_python_hwc/answers/hwc406.py +66 -0
- bai_python_hwc/answers/hwc407.py +49 -0
- bai_python_hwc/answers/hwc408.py +67 -0
- bai_python_hwc/answers/hwc409.py +51 -0
- bai_python_hwc/answers/hwc410.py +52 -0
- bai_python_hwc/answers/hwc411.py +57 -0
- bai_python_hwc/answers/hwc412.py +53 -0
- bai_python_hwc/answers/hwc413.py +65 -0
- bai_python_hwc/answers/hwc414.py +50 -0
- bai_python_hwc/answers/hwc415.py +61 -0
- bai_python_hwc/answers/hwc416.py +69 -0
- bai_python_hwc/answers/hwc418.py +47 -0
- bai_python_hwc/answers/hwc419.py +62 -0
- bai_python_hwc/answers/hwc421.py +51 -0
- bai_python_hwc/answers/hwc424.py +48 -0
- bai_python_hwc/answers/hwc501.py +63 -0
- bai_python_hwc/answers/hwc502.py +69 -0
- bai_python_hwc/answers/hwc503.py +75 -0
- bai_python_hwc/answers/hwc504.py +52 -0
- bai_python_hwc/answers/hwc505.py +63 -0
- bai_python_hwc/answers/hwc506.py +61 -0
- bai_python_hwc/answers/hwc508.py +60 -0
- bai_python_hwc/answers/hwc509.py +85 -0
- bai_python_hwc/answers/hwc510.py +56 -0
- bai_python_hwc/answers/hwc511.py +52 -0
- bai_python_hwc/answers/hwc513.py +63 -0
- bai_python_hwc/answers/hwc514.py +74 -0
- bai_python_hwc/answers/hwc515.py +83 -0
- bai_python_hwc/answers/hwc516.py +67 -0
- bai_python_hwc/answers/hwc517.py +46 -0
- bai_python_hwc/answers/hwc520.py +54 -0
- bai_python_hwc/answers/hwc526.py +58 -0
- bai_python_hwc/attachments/hwc424.pdf +0 -0
- bai_python_hwc/attachments/hwc501.pdf +0 -0
- bai_python_hwc/questions/hwc101.txt +17 -0
- bai_python_hwc/questions/hwc103.txt +27 -0
- bai_python_hwc/questions/hwc104.txt +22 -0
- bai_python_hwc/questions/hwc105.txt +23 -0
- bai_python_hwc/questions/hwc106.txt +26 -0
- bai_python_hwc/questions/hwc107.txt +29 -0
- bai_python_hwc/questions/hwc108.txt +18 -0
- bai_python_hwc/questions/hwc109.txt +24 -0
- bai_python_hwc/questions/hwc110.txt +16 -0
- bai_python_hwc/questions/hwc111.txt +25 -0
- bai_python_hwc/questions/hwc112.txt +13 -0
- bai_python_hwc/questions/hwc113.txt +28 -0
- bai_python_hwc/questions/hwc114.txt +35 -0
- bai_python_hwc/questions/hwc115.txt +15 -0
- bai_python_hwc/questions/hwc116.txt +13 -0
- bai_python_hwc/questions/hwc117.txt +14 -0
- bai_python_hwc/questions/hwc118.txt +25 -0
- bai_python_hwc/questions/hwc119.txt +18 -0
- bai_python_hwc/questions/hwc120.txt +23 -0
- bai_python_hwc/questions/hwc121.txt +26 -0
- bai_python_hwc/questions/hwc122.txt +21 -0
- bai_python_hwc/questions/hwc123.txt +21 -0
- bai_python_hwc/questions/hwc124.txt +19 -0
- bai_python_hwc/questions/hwc125.txt +31 -0
- bai_python_hwc/questions/hwc126.txt +18 -0
- bai_python_hwc/questions/hwc127.txt +17 -0
- bai_python_hwc/questions/hwc128.txt +14 -0
- bai_python_hwc/questions/hwc130.txt +23 -0
- bai_python_hwc/questions/hwc131.txt +19 -0
- bai_python_hwc/questions/hwc132.txt +16 -0
- bai_python_hwc/questions/hwc133.txt +39 -0
- bai_python_hwc/questions/hwc134.txt +22 -0
- bai_python_hwc/questions/hwc135.txt +29 -0
- bai_python_hwc/questions/hwc136.txt +20 -0
- bai_python_hwc/questions/hwc201.txt +20 -0
- bai_python_hwc/questions/hwc202.txt +25 -0
- bai_python_hwc/questions/hwc203.txt +26 -0
- bai_python_hwc/questions/hwc204.txt +32 -0
- bai_python_hwc/questions/hwc205.txt +28 -0
- bai_python_hwc/questions/hwc206.txt +28 -0
- bai_python_hwc/questions/hwc207.txt +16 -0
- bai_python_hwc/questions/hwc208.txt +27 -0
- bai_python_hwc/questions/hwc209.txt +15 -0
- bai_python_hwc/questions/hwc210.txt +28 -0
- bai_python_hwc/questions/hwc211.txt +35 -0
- bai_python_hwc/questions/hwc212.txt +29 -0
- bai_python_hwc/questions/hwc213.txt +27 -0
- bai_python_hwc/questions/hwc214.txt +27 -0
- bai_python_hwc/questions/hwc215.txt +28 -0
- bai_python_hwc/questions/hwc216.txt +22 -0
- bai_python_hwc/questions/hwc217.txt +17 -0
- bai_python_hwc/questions/hwc218.txt +18 -0
- bai_python_hwc/questions/hwc219.txt +22 -0
- bai_python_hwc/questions/hwc220.txt +28 -0
- bai_python_hwc/questions/hwc221.txt +18 -0
- bai_python_hwc/questions/hwc222.txt +20 -0
- bai_python_hwc/questions/hwc223.txt +18 -0
- bai_python_hwc/questions/hwc224.txt +23 -0
- bai_python_hwc/questions/hwc225.txt +26 -0
- bai_python_hwc/questions/hwc226.txt +18 -0
- bai_python_hwc/questions/hwc227.txt +15 -0
- bai_python_hwc/questions/hwc228.txt +16 -0
- bai_python_hwc/questions/hwc229.txt +20 -0
- bai_python_hwc/questions/hwc230.txt +18 -0
- bai_python_hwc/questions/hwc231.txt +13 -0
- bai_python_hwc/questions/hwc232.txt +19 -0
- bai_python_hwc/questions/hwc233.txt +21 -0
- bai_python_hwc/questions/hwc234.txt +27 -0
- bai_python_hwc/questions/hwc235.txt +18 -0
- bai_python_hwc/questions/hwc236.txt +23 -0
- bai_python_hwc/questions/hwc237.txt +28 -0
- bai_python_hwc/questions/hwc238.txt +25 -0
- bai_python_hwc/questions/hwc239.txt +28 -0
- bai_python_hwc/questions/hwc240.txt +21 -0
- bai_python_hwc/questions/hwc241.txt +25 -0
- bai_python_hwc/questions/hwc242.txt +23 -0
- bai_python_hwc/questions/hwc243.txt +35 -0
- bai_python_hwc/questions/hwc244.txt +25 -0
- bai_python_hwc/questions/hwc245.txt +24 -0
- bai_python_hwc/questions/hwc246.txt +28 -0
- bai_python_hwc/questions/hwc247.txt +51 -0
- bai_python_hwc/questions/hwc301.txt +23 -0
- bai_python_hwc/questions/hwc302.txt +26 -0
- bai_python_hwc/questions/hwc303.txt +32 -0
- bai_python_hwc/questions/hwc304.txt +32 -0
- bai_python_hwc/questions/hwc305.txt +31 -0
- bai_python_hwc/questions/hwc306.txt +31 -0
- bai_python_hwc/questions/hwc307.txt +29 -0
- bai_python_hwc/questions/hwc308.txt +30 -0
- bai_python_hwc/questions/hwc309.txt +25 -0
- bai_python_hwc/questions/hwc310.txt +15 -0
- bai_python_hwc/questions/hwc311.txt +23 -0
- bai_python_hwc/questions/hwc312.txt +19 -0
- bai_python_hwc/questions/hwc313.txt +26 -0
- bai_python_hwc/questions/hwc314.txt +27 -0
- bai_python_hwc/questions/hwc315.txt +21 -0
- bai_python_hwc/questions/hwc316.txt +36 -0
- bai_python_hwc/questions/hwc317.txt +28 -0
- bai_python_hwc/questions/hwc318.txt +27 -0
- bai_python_hwc/questions/hwc319.txt +26 -0
- bai_python_hwc/questions/hwc320.txt +42 -0
- bai_python_hwc/questions/hwc321.txt +27 -0
- bai_python_hwc/questions/hwc322.txt +26 -0
- bai_python_hwc/questions/hwc323.txt +24 -0
- bai_python_hwc/questions/hwc324.txt +40 -0
- bai_python_hwc/questions/hwc325.txt +21 -0
- bai_python_hwc/questions/hwc326.txt +25 -0
- bai_python_hwc/questions/hwc327.txt +16 -0
- bai_python_hwc/questions/hwc328.txt +15 -0
- bai_python_hwc/questions/hwc329.txt +26 -0
- bai_python_hwc/questions/hwc330.txt +27 -0
- bai_python_hwc/questions/hwc332.txt +26 -0
- bai_python_hwc/questions/hwc401.txt +25 -0
- bai_python_hwc/questions/hwc402.txt +24 -0
- bai_python_hwc/questions/hwc403.txt +37 -0
- bai_python_hwc/questions/hwc404.txt +23 -0
- bai_python_hwc/questions/hwc405.txt +29 -0
- bai_python_hwc/questions/hwc406.txt +34 -0
- bai_python_hwc/questions/hwc407.txt +24 -0
- bai_python_hwc/questions/hwc408.txt +28 -0
- bai_python_hwc/questions/hwc409.txt +25 -0
- bai_python_hwc/questions/hwc410.txt +23 -0
- bai_python_hwc/questions/hwc411.txt +34 -0
- bai_python_hwc/questions/hwc412.txt +29 -0
- bai_python_hwc/questions/hwc413.txt +28 -0
- bai_python_hwc/questions/hwc414.txt +27 -0
- bai_python_hwc/questions/hwc415.txt +27 -0
- bai_python_hwc/questions/hwc416.txt +36 -0
- bai_python_hwc/questions/hwc418.txt +25 -0
- bai_python_hwc/questions/hwc419.txt +28 -0
- bai_python_hwc/questions/hwc421.txt +23 -0
- bai_python_hwc/questions/hwc424.txt +20 -0
- bai_python_hwc/questions/hwc501.txt +23 -0
- bai_python_hwc/questions/hwc502.txt +41 -0
- bai_python_hwc/questions/hwc503.txt +36 -0
- bai_python_hwc/questions/hwc504.txt +18 -0
- bai_python_hwc/questions/hwc505.txt +25 -0
- bai_python_hwc/questions/hwc506.txt +32 -0
- bai_python_hwc/questions/hwc508.txt +24 -0
- bai_python_hwc/questions/hwc509.txt +42 -0
- bai_python_hwc/questions/hwc510.txt +25 -0
- bai_python_hwc/questions/hwc511.txt +23 -0
- bai_python_hwc/questions/hwc513.txt +25 -0
- bai_python_hwc/questions/hwc514.txt +35 -0
- bai_python_hwc/questions/hwc515.txt +46 -0
- bai_python_hwc/questions/hwc516.txt +26 -0
- bai_python_hwc/questions/hwc517.txt +20 -0
- bai_python_hwc/questions/hwc520.txt +27 -0
- bai_python_hwc/questions/hwc526.txt +36 -0
- bai_python_hwc-1.0.0.dist-info/METADATA +41 -0
- bai_python_hwc-1.0.0.dist-info/RECORD +305 -0
- bai_python_hwc-1.0.0.dist-info/WHEEL +5 -0
- bai_python_hwc-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
给你一个 严格升序排列 的正整数数组 arr 和一个整数 k 。
|
|
16
|
+
|
|
17
|
+
请你找到这个数组里第 k 个缺失的正整数。
|
|
18
|
+
(正整数从 1 开始数:1, 2, 3, 4, ...,数组里没出现的就叫"缺失的",按从小到大数第 k 个。)
|
|
19
|
+
|
|
20
|
+
示例 1:
|
|
21
|
+
|
|
22
|
+
输入:arr = [2,3,4,7,11], k = 5
|
|
23
|
+
输出:9
|
|
24
|
+
解释:缺失的正整数包括 [1,5,6,8,9,10,12,13,...] 。第 5 个缺失的正整数为 9 。
|
|
25
|
+
示例 2:
|
|
26
|
+
|
|
27
|
+
输入:arr = [1,2,3,4], k = 2
|
|
28
|
+
输出:6
|
|
29
|
+
解释:缺失的正整数包括 [5,6,7,...] 。第 2 个缺失的正整数为 6 。
|
|
30
|
+
'''
|
|
31
|
+
|
|
32
|
+
# 参考答案
|
|
33
|
+
def TEST_DO_NOT_CHANGE(arr,k):
|
|
34
|
+
print(arr,k)
|
|
35
|
+
rlt = None
|
|
36
|
+
##########start下面可以改动
|
|
37
|
+
|
|
38
|
+
left, right = 0, len(arr)
|
|
39
|
+
while left < right:
|
|
40
|
+
middle = (left + right) // 2
|
|
41
|
+
missing = arr[middle] - (middle + 1)
|
|
42
|
+
if missing < k:
|
|
43
|
+
left = middle + 1
|
|
44
|
+
else:
|
|
45
|
+
right = middle
|
|
46
|
+
rlt = left + k
|
|
47
|
+
|
|
48
|
+
##########end上面可以改动
|
|
49
|
+
return rlt
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
if __name__ == "__main__":
|
|
53
|
+
###########下面可以修改
|
|
54
|
+
arr = [2,3,4,7,11]
|
|
55
|
+
k = 5
|
|
56
|
+
print(TEST_DO_NOT_CHANGE(arr,k))
|
|
57
|
+
# 题号:hwc208
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在第10次落地时,共经过多少米?
|
|
16
|
+
第10次反弹多高?请将两问的结果(数字)保存到lst_rlt列表并输出。
|
|
17
|
+
输出结果示例:[第10次落地时经过的总米数,第10次反弹高度](输出结果中仅包含阿拉伯数字,不需要单位)
|
|
18
|
+
'''
|
|
19
|
+
|
|
20
|
+
# 参考答案
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def TEST_DO_NOT_CHANGE():
|
|
25
|
+
lst_rlt=[]
|
|
26
|
+
##########start下面可以改动
|
|
27
|
+
|
|
28
|
+
height = distance = 100
|
|
29
|
+
for _ in range(9):
|
|
30
|
+
height /= 2
|
|
31
|
+
distance += 2 * height
|
|
32
|
+
lst_rlt = [distance, height / 2]
|
|
33
|
+
|
|
34
|
+
##########end上面可以改动
|
|
35
|
+
return lst_rlt
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
if __name__ == "__main__":
|
|
40
|
+
###########下面可以修改
|
|
41
|
+
print(TEST_DO_NOT_CHANGE())
|
|
42
|
+
# 题号:hwc209
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'''
|
|
2
|
+
请只在 "
|
|
3
|
+
##########start下面可以改动
|
|
4
|
+
|
|
5
|
+
##########end上面可以改动 "
|
|
6
|
+
|
|
7
|
+
中间部分作答,作答行数自由调整
|
|
8
|
+
|
|
9
|
+
请不要使用 input() 函数
|
|
10
|
+
|
|
11
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
12
|
+
|
|
13
|
+
题目:
|
|
14
|
+
给你两个字符串 haystack 和 needle ,请你在 haystack 字符串中找出 needle 字符串出现的第一个位置(下标从 0 开始)。
|
|
15
|
+
如果不存在,则返回 -1 。
|
|
16
|
+
|
|
17
|
+
示例 1:
|
|
18
|
+
|
|
19
|
+
输入: haystack = "hello", needle = "ll"
|
|
20
|
+
输出: 2
|
|
21
|
+
|
|
22
|
+
示例 2:
|
|
23
|
+
|
|
24
|
+
输入: haystack = "aaaaa", needle = "bba"
|
|
25
|
+
输出: -1
|
|
26
|
+
|
|
27
|
+
示例 3:
|
|
28
|
+
输入: haystack = "", needle = ""
|
|
29
|
+
输出: 0
|
|
30
|
+
'''
|
|
31
|
+
|
|
32
|
+
# 参考答案
|
|
33
|
+
def TEST_DO_NOT_CHANGE(haystack, needle):
|
|
34
|
+
res = 0
|
|
35
|
+
##########start下面可以改动
|
|
36
|
+
|
|
37
|
+
res = haystack.find(needle)
|
|
38
|
+
|
|
39
|
+
##########end上面可以改动
|
|
40
|
+
return res
|
|
41
|
+
|
|
42
|
+
if __name__ == '__main__':
|
|
43
|
+
###########下面可以修改
|
|
44
|
+
print(TEST_DO_NOT_CHANGE("hello","ll"))
|
|
45
|
+
print(TEST_DO_NOT_CHANGE("aaaaa", needle = "bba"))
|
|
46
|
+
print(TEST_DO_NOT_CHANGE(haystack = "", needle = ""))
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
统计有序矩阵中的负数 给你一个 m * n 的矩阵(二维列表)grid,矩阵中每一行、每一列都是按从大到小排好的(相邻元素允许相等,即"非递增")。
|
|
16
|
+
请你统计并返回 grid 中 负数 的数目。
|
|
17
|
+
|
|
18
|
+
示例 1:
|
|
19
|
+
|
|
20
|
+
输入: grid = [[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]
|
|
21
|
+
输出: 8
|
|
22
|
+
解释: 矩阵中共有 8 个负数。
|
|
23
|
+
|
|
24
|
+
示例 2:
|
|
25
|
+
|
|
26
|
+
输入: grid = [[3,2],[1,0]]
|
|
27
|
+
输出: 0
|
|
28
|
+
|
|
29
|
+
示例 3:
|
|
30
|
+
|
|
31
|
+
输入: grid = [[1,-1],[-1,-1]]
|
|
32
|
+
输出: 3
|
|
33
|
+
|
|
34
|
+
示例 4:
|
|
35
|
+
|
|
36
|
+
输入: grid = [[-1]]
|
|
37
|
+
输出: 1
|
|
38
|
+
'''
|
|
39
|
+
|
|
40
|
+
# 参考答案
|
|
41
|
+
def TEST_DO_NOT_CHANGE(grid):
|
|
42
|
+
res = 0
|
|
43
|
+
##########start下面可以改动
|
|
44
|
+
|
|
45
|
+
if grid and grid[0]:
|
|
46
|
+
row, col = len(grid) - 1, 0
|
|
47
|
+
while row >= 0 and col < len(grid[0]):
|
|
48
|
+
if grid[row][col] < 0:
|
|
49
|
+
res += len(grid[0]) - col
|
|
50
|
+
row -= 1
|
|
51
|
+
else:
|
|
52
|
+
col += 1
|
|
53
|
+
|
|
54
|
+
##########end上面可以改动
|
|
55
|
+
return res
|
|
56
|
+
|
|
57
|
+
if __name__ == '__main__':
|
|
58
|
+
###########下面可以修改
|
|
59
|
+
print(TEST_DO_NOT_CHANGE([[4,3,2,-1],[3,2,1,-1],[1,1,-1,-2],[-1,-1,-2,-3]]))
|
|
60
|
+
print(TEST_DO_NOT_CHANGE([[3,2],[1,0]]))
|
|
61
|
+
print(TEST_DO_NOT_CHANGE([[1,-1],[-1,-1]]))
|
|
62
|
+
print(TEST_DO_NOT_CHANGE([[-1]]))
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
给定一个包含大写字母和小写字母的字符串,找到通过这些字母构造成的最长的回文串。
|
|
15
|
+
(回文串:正着读和反着读完全一样的字符串,例如 "abcba"、"noon"。)
|
|
16
|
+
只需返回这个最长回文串的 长度。
|
|
17
|
+
|
|
18
|
+
在构造过程中,请注意区分大小写。比如 "Aa" 不能当做一个回文字符串。
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
示例 1:
|
|
23
|
+
|
|
24
|
+
输入:
|
|
25
|
+
"abccccdd"
|
|
26
|
+
|
|
27
|
+
输出:
|
|
28
|
+
7
|
|
29
|
+
|
|
30
|
+
解释:
|
|
31
|
+
我们可以构造的最长的回文串是"dccaccd", 它的长度是 7。
|
|
32
|
+
'''
|
|
33
|
+
|
|
34
|
+
# 参考答案
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def TEST_DO_NOT_CHANGE(s):
|
|
39
|
+
rlt = None
|
|
40
|
+
##########start下面可以改动
|
|
41
|
+
|
|
42
|
+
from collections import Counter
|
|
43
|
+
|
|
44
|
+
counts = Counter(s).values()
|
|
45
|
+
pairs = sum(count // 2 for count in counts)
|
|
46
|
+
rlt = 2 * pairs + (2 * pairs < len(s))
|
|
47
|
+
|
|
48
|
+
##########end上面可以改动
|
|
49
|
+
return rlt
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
if __name__ == "__main__":
|
|
55
|
+
###########下面可以修改
|
|
56
|
+
s = "abccccdd"
|
|
57
|
+
print(TEST_DO_NOT_CHANGE(s))
|
|
58
|
+
# 题号:hwc212
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
两个整数之间的汉明距离指的是这两个数字对应二进制位不同的位置的数目。
|
|
16
|
+
|
|
17
|
+
给出两个整数 x 和 y,计算它们之间的汉明距离。
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
示例:
|
|
21
|
+
|
|
22
|
+
输入: x = 1, y = 4
|
|
23
|
+
|
|
24
|
+
输出: 2
|
|
25
|
+
|
|
26
|
+
解释:
|
|
27
|
+
1 (0 0 0 1)
|
|
28
|
+
4 (0 1 0 0)
|
|
29
|
+
它们的二进制表示中有两个位不同,所以汉明距离为 2。
|
|
30
|
+
'''
|
|
31
|
+
|
|
32
|
+
# 参考答案
|
|
33
|
+
|
|
34
|
+
def TEST_DO_NOT_CHANGE(x,y):
|
|
35
|
+
print(x,y)
|
|
36
|
+
rlt = None
|
|
37
|
+
##########start下面可以改动
|
|
38
|
+
|
|
39
|
+
different_bits = x ^ y
|
|
40
|
+
if different_bits < 0:
|
|
41
|
+
# 负数按能共同容纳两个输入的最短有符号补码宽度解释。
|
|
42
|
+
width = max(
|
|
43
|
+
value.bit_length() + 1 if value >= 0 else (~value).bit_length() + 1
|
|
44
|
+
for value in (x, y)
|
|
45
|
+
)
|
|
46
|
+
different_bits &= (1 << width) - 1
|
|
47
|
+
rlt = different_bits.bit_count()
|
|
48
|
+
|
|
49
|
+
##########end上面可以改动
|
|
50
|
+
return rlt
|
|
51
|
+
|
|
52
|
+
if __name__ == "__main__":
|
|
53
|
+
###########下面可以修改
|
|
54
|
+
print(TEST_DO_NOT_CHANGE(1,4))
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目
|
|
15
|
+
给定一个非负整数 numRows,生成杨辉三角的前 numRows 行。
|
|
16
|
+
在杨辉三角中,每个数是它左上方和右上方的数的和。
|
|
17
|
+
|
|
18
|
+
示例:
|
|
19
|
+
输入: 5
|
|
20
|
+
输出:
|
|
21
|
+
[
|
|
22
|
+
[1],
|
|
23
|
+
[1,1],
|
|
24
|
+
[1,2,1],
|
|
25
|
+
[1,3,3,1],
|
|
26
|
+
[1,4,6,4,1]
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
注意 上面的输出只是为了好看,无需输出的list打印出来像上面一样。当然如果你有空,也可以尝试一下!
|
|
30
|
+
'''
|
|
31
|
+
|
|
32
|
+
# 参考答案
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def TEST_DO_NOT_CHANGE(numRows):
|
|
37
|
+
lst_rlt = []
|
|
38
|
+
##########start下面可以改动
|
|
39
|
+
|
|
40
|
+
for i in range(numRows):
|
|
41
|
+
row = [1] * (i + 1)
|
|
42
|
+
if i > 1:
|
|
43
|
+
previous = lst_rlt[-1]
|
|
44
|
+
for j in range(1, i):
|
|
45
|
+
row[j] = previous[j - 1] + previous[j]
|
|
46
|
+
lst_rlt.append(row)
|
|
47
|
+
|
|
48
|
+
##########end上面可以改动
|
|
49
|
+
return lst_rlt
|
|
50
|
+
|
|
51
|
+
if __name__ == "__main__":
|
|
52
|
+
###########下面可以修改
|
|
53
|
+
print(TEST_DO_NOT_CHANGE(5))
|
|
54
|
+
print(TEST_DO_NOT_CHANGE(1))
|
|
55
|
+
# 题号:hwc214
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
给定一个数组 prices ,它的第 i 个元素prices[i] 表示一支给定股票第 i 天的价格。
|
|
16
|
+
你只能选择某一天买入这只股票,并选择在未来的某一个不同的日子卖出该股票。设计一个算法来计算你所能获取的最大利润。
|
|
17
|
+
返回你可以从这笔交易中获取的最大利润。如果你不能获取任何利润,返回 0 。
|
|
18
|
+
|
|
19
|
+
示例 1:
|
|
20
|
+
|
|
21
|
+
输入:[7,1,5,3,6,4]
|
|
22
|
+
输出:5
|
|
23
|
+
解释:在第 2 天(股票价格 = 1)的时候买入,在第 5 天(股票价格 = 6)的时候卖出,最大利润 = 6-1 = 5 。
|
|
24
|
+
注意利润不能是 7-1 = 6,因为价格 7 出现在价格 1 之前,不能先卖出后买入;同时,卖出日必须晚于买入日。
|
|
25
|
+
|
|
26
|
+
示例 2:
|
|
27
|
+
|
|
28
|
+
输入:prices = [7,6,4,3,1]
|
|
29
|
+
输出:0
|
|
30
|
+
解释:在这种情况下, 没有交易完成, 所以最大利润为 0。
|
|
31
|
+
'''
|
|
32
|
+
|
|
33
|
+
# 参考答案
|
|
34
|
+
def TEST_DO_NOT_CHANGE(prices):
|
|
35
|
+
print(prices)
|
|
36
|
+
rlt = None
|
|
37
|
+
##########start下面可以改动
|
|
38
|
+
|
|
39
|
+
if not prices:
|
|
40
|
+
return 0
|
|
41
|
+
lowest = prices[0]
|
|
42
|
+
rlt = 0
|
|
43
|
+
for price in prices:
|
|
44
|
+
rlt = max(rlt, price - lowest)
|
|
45
|
+
lowest = min(lowest, price)
|
|
46
|
+
|
|
47
|
+
##########end上面可以改动
|
|
48
|
+
return rlt
|
|
49
|
+
|
|
50
|
+
if __name__ == "__main__":
|
|
51
|
+
###########下面可以修改
|
|
52
|
+
print(TEST_DO_NOT_CHANGE([7,1,5,3,6,4]))
|
|
53
|
+
print(TEST_DO_NOT_CHANGE([7,6,4,3,1]))
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:《最小差》
|
|
15
|
+
|
|
16
|
+
问题描述
|
|
17
|
+
给定两个整数数组 a 和 b,计算具有最小差绝对值的一对数值(每个数组中取一个值),并返回 abs(a-b) 的最小值。
|
|
18
|
+
|
|
19
|
+
示例:
|
|
20
|
+
|
|
21
|
+
输入:[1, 3, 15, 11, 2], [23, 127, 235, 19, 8]
|
|
22
|
+
输出:3
|
|
23
|
+
|
|
24
|
+
原因:即数值对(11, 8)
|
|
25
|
+
'''
|
|
26
|
+
|
|
27
|
+
# 参考答案
|
|
28
|
+
def TEST_DO_NOT_CHANGE(lst_1,lst_2):
|
|
29
|
+
result = None
|
|
30
|
+
##########start下面可以改动
|
|
31
|
+
|
|
32
|
+
first, second = sorted(lst_1), sorted(lst_2)
|
|
33
|
+
i = j = 0
|
|
34
|
+
result = abs(first[0] - second[0])
|
|
35
|
+
while i < len(first) and j < len(second):
|
|
36
|
+
difference = first[i] - second[j]
|
|
37
|
+
result = min(result, abs(difference))
|
|
38
|
+
if difference == 0:
|
|
39
|
+
break
|
|
40
|
+
if difference < 0:
|
|
41
|
+
i += 1
|
|
42
|
+
else:
|
|
43
|
+
j += 1
|
|
44
|
+
|
|
45
|
+
##########end上面可以改动
|
|
46
|
+
return result
|
|
47
|
+
|
|
48
|
+
if __name__ == "__main__":
|
|
49
|
+
###########下面可以修改
|
|
50
|
+
print(TEST_DO_NOT_CHANGE([1, 3, 15, 11, 2], [23, 127, 235, 19, 8]))
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
给一个不多于5位的正整数,要求:一、求它是几位数(结果仅需输出阿拉伯数字),二、逆序打印出各位数字。
|
|
16
|
+
请将最终结果合并保存到lst_rlt列表中。
|
|
17
|
+
|
|
18
|
+
输出结果示例:54321的输出结果为[5, 1, 2, 3, 4, 5],其中首位的5表示总位数,自第二个元素起依次为该正整数的个、十、百、千、万位数字。
|
|
19
|
+
程序分析:学会分解出每一位数。
|
|
20
|
+
'''
|
|
21
|
+
|
|
22
|
+
# 参考答案
|
|
23
|
+
|
|
24
|
+
def TEST_DO_NOT_CHANGE(num_input):
|
|
25
|
+
lst_rlt=[]
|
|
26
|
+
print(num_input)
|
|
27
|
+
##########start下面可以改动
|
|
28
|
+
|
|
29
|
+
digits = [int(digit) for digit in reversed(str(num_input))]
|
|
30
|
+
lst_rlt = [len(digits)] + digits
|
|
31
|
+
|
|
32
|
+
##########end上面可以改动
|
|
33
|
+
return lst_rlt
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
if __name__ == "__main__":
|
|
37
|
+
###########下面可以修改
|
|
38
|
+
print (TEST_DO_NOT_CHANGE(54321))
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'''
|
|
2
|
+
请只在 "
|
|
3
|
+
##########start下面可以改动
|
|
4
|
+
|
|
5
|
+
##########end上面可以改动 "
|
|
6
|
+
|
|
7
|
+
中间部分作答,作答行数自由调整
|
|
8
|
+
|
|
9
|
+
请不要使用 input() 函数
|
|
10
|
+
|
|
11
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
12
|
+
|
|
13
|
+
题目:括号匹配
|
|
14
|
+
|
|
15
|
+
编写一个 Python 函数,用于检查给定的字符串中的括号是否匹配。字符串中允许包含小括号 ()、中括号 [] 和大括号 {},并且括号可以嵌套。
|
|
16
|
+
|
|
17
|
+
检查时,要确保每个左括号都有与之匹配的右括号,并且括号的嵌套关系必须正确。例如,字符串 "()[]{}" 是括号匹配的,而字符串 "{[()]}" 也是括号匹配的,但字符串 "{[)]}" 不是括号匹配的。
|
|
18
|
+
|
|
19
|
+
请编写一个函数 TEST_DO_NOT_CHANGE(s),其中 s 是输入的字符串,函数应该返回布尔值,表示括号是否匹配。
|
|
20
|
+
'''
|
|
21
|
+
|
|
22
|
+
# 参考答案
|
|
23
|
+
def TEST_DO_NOT_CHANGE(s):
|
|
24
|
+
stack = [] # 使用栈来辅助判断括号匹配
|
|
25
|
+
##########start下面可以改动
|
|
26
|
+
|
|
27
|
+
closing = {")": "(", "]": "[", "}": "{"}
|
|
28
|
+
for char in s:
|
|
29
|
+
if char in closing.values():
|
|
30
|
+
stack.append(char)
|
|
31
|
+
elif char in closing:
|
|
32
|
+
if not stack or stack.pop() != closing[char]:
|
|
33
|
+
return False
|
|
34
|
+
|
|
35
|
+
##########end上面可以改动
|
|
36
|
+
return not stack # 最后栈中应该为空
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
if __name__ == "__main__":
|
|
40
|
+
###########下面可以修改
|
|
41
|
+
print(TEST_DO_NOT_CHANGE("()[]{}")) # 应该输出 True
|
|
42
|
+
print(TEST_DO_NOT_CHANGE("{[()]}")) # 应该输出 True
|
|
43
|
+
print(TEST_DO_NOT_CHANGE("{[)]}")) # 应该输出 False
|
|
44
|
+
# 题号:hwc218
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
|
|
16
|
+
给定一个整数数组 nums ,找到和最大的一段 连续子数组(即数组中连续的一段,最少包含一个元素),返回这个最大和。
|
|
17
|
+
|
|
18
|
+
提示:可以从左往右扫描,随时记录"以当前元素结尾的最大和"——如果之前的和已经变成负数,就丢掉它从当前元素重新开始累加。
|
|
19
|
+
|
|
20
|
+
示例 1:
|
|
21
|
+
|
|
22
|
+
输入: nums = [-2,1,-3,4,-1,2,1,-5,4]
|
|
23
|
+
输出: 6
|
|
24
|
+
解释: 连续子数组 [4,-1,2,1] 的和最大,为 6 。
|
|
25
|
+
'''
|
|
26
|
+
|
|
27
|
+
# 参考答案
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def TEST_DO_NOT_CHANGE(nums):
|
|
31
|
+
rlt = None
|
|
32
|
+
##########start下面可以改动
|
|
33
|
+
|
|
34
|
+
rlt = current = nums[0]
|
|
35
|
+
for i in range(1, len(nums)):
|
|
36
|
+
value = nums[i]
|
|
37
|
+
current = max(value, current + value)
|
|
38
|
+
rlt = max(rlt, current)
|
|
39
|
+
|
|
40
|
+
##########end上面可以改动
|
|
41
|
+
return rlt
|
|
42
|
+
|
|
43
|
+
if __name__ == "__main__":
|
|
44
|
+
###########下面可以修改
|
|
45
|
+
print(TEST_DO_NOT_CHANGE([-2,1,-3,4,-1,2,1,-5,4])) # 值应该为6
|
|
46
|
+
print(TEST_DO_NOT_CHANGE([1])) # 值应该为1
|
|
47
|
+
print(TEST_DO_NOT_CHANGE([0,2,3,-3,4,-5,6,-2,8,-4,5,-3,3,3,2,-5,4,-3,3])) # 值应该为19
|
|
48
|
+
print(TEST_DO_NOT_CHANGE([-1])) #值应该为-1
|
|
49
|
+
print(TEST_DO_NOT_CHANGE([-100000])) # 值应该为-100000
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
给定一个未经排序的整数数组,找到最长的 连续递增子序列,并返回它的长度。
|
|
15
|
+
|
|
16
|
+
连续递增子序列:指数组中 连续的一段,且其中每个数都严格比前一个大(例如 [1,3,5])。注意必须是连续的一段,不能跳着挑。
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
示例 1:
|
|
21
|
+
|
|
22
|
+
输入:nums = [1,3,5,4,7]
|
|
23
|
+
输出:3
|
|
24
|
+
解释:最长连续递增序列是 [1,3,5], 长度为3。
|
|
25
|
+
尽管 [1,3,5,7] 也是升序的子序列, 但它不是连续的,因为 5 和 7 在原数组里被 4 隔开。
|
|
26
|
+
示例 2:
|
|
27
|
+
|
|
28
|
+
输入:nums = [2,2,2,2,2]
|
|
29
|
+
输出:1
|
|
30
|
+
解释:最长连续递增序列是 [2], 长度为1。
|
|
31
|
+
'''
|
|
32
|
+
|
|
33
|
+
# 参考答案
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def TEST_DO_NOT_CHANGE(nums):
|
|
38
|
+
print(nums)
|
|
39
|
+
rlt = None
|
|
40
|
+
##########start下面可以改动
|
|
41
|
+
|
|
42
|
+
rlt = run = 0
|
|
43
|
+
previous = None
|
|
44
|
+
for value in nums:
|
|
45
|
+
run = run + 1 if previous is not None and value > previous else 1
|
|
46
|
+
rlt = max(rlt, run)
|
|
47
|
+
previous = value
|
|
48
|
+
|
|
49
|
+
##########end上面可以改动
|
|
50
|
+
return rlt
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
if __name__ == "__main__":
|
|
56
|
+
###########下面可以修改
|
|
57
|
+
nums = [1,3,5,4,7]
|
|
58
|
+
print(TEST_DO_NOT_CHANGE(nums))
|