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,56 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
给你一个字符串 s,请你将 s 分割成一些子串,使每个子串都是 回文串 。返回 s 所有可能的分割方案。
|
|
16
|
+
注意,回文串 是正着读和反着读都一样的字符串。
|
|
17
|
+
当 s 为空字符串时,返回包含一个空分割方案的列表 `[[]]`。
|
|
18
|
+
|
|
19
|
+
示例 1:
|
|
20
|
+
|
|
21
|
+
输入:s = "aab"
|
|
22
|
+
输出:[["a","a","b"],["aa","b"]]
|
|
23
|
+
|
|
24
|
+
示例 2:
|
|
25
|
+
|
|
26
|
+
输入:s = "a"
|
|
27
|
+
输出:[["a"]]
|
|
28
|
+
'''
|
|
29
|
+
|
|
30
|
+
# 参考答案
|
|
31
|
+
def TEST_DO_NOT_CHANGE(s):
|
|
32
|
+
lst_rlt = None
|
|
33
|
+
##########start下面可以改动
|
|
34
|
+
|
|
35
|
+
lst_rlt = []
|
|
36
|
+
|
|
37
|
+
def search(start, chosen):
|
|
38
|
+
if start == len(s):
|
|
39
|
+
lst_rlt.append(chosen.copy())
|
|
40
|
+
return
|
|
41
|
+
for end in range(start + 1, len(s) + 1):
|
|
42
|
+
part = s[start:end]
|
|
43
|
+
if part == part[::-1]:
|
|
44
|
+
chosen.append(part)
|
|
45
|
+
search(end, chosen)
|
|
46
|
+
chosen.pop()
|
|
47
|
+
|
|
48
|
+
search(0, [])
|
|
49
|
+
|
|
50
|
+
##########end上面可以改动
|
|
51
|
+
return lst_rlt
|
|
52
|
+
|
|
53
|
+
if __name__ == "__main__":
|
|
54
|
+
###########下面可以修改
|
|
55
|
+
s = "aab"
|
|
56
|
+
print(TEST_DO_NOT_CHANGE(s))
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:移掉 K 位数字
|
|
15
|
+
给你一个以字符串表示的非负整数num和一个整数k,移除这个数中的k位数字,使得剩下的数字最小。请你以字符串形式返回这个最小的数字
|
|
16
|
+
|
|
17
|
+
示例:
|
|
18
|
+
输入:num = "1432219", k = 3
|
|
19
|
+
输出:"1219"
|
|
20
|
+
解释:移除掉三个数字 4, 3, 和 2 形成一个新的最小的数字 1219 。
|
|
21
|
+
|
|
22
|
+
提示:
|
|
23
|
+
1 <= k <= num.length <= 105
|
|
24
|
+
num仅由若干位数字(0 - 9)组成
|
|
25
|
+
除了0本身之外,num不含任何前导零
|
|
26
|
+
'''
|
|
27
|
+
|
|
28
|
+
# 参考答案
|
|
29
|
+
|
|
30
|
+
def TEST_DO_NOT_CHANGE(num, k):
|
|
31
|
+
lst_rlt = None
|
|
32
|
+
##########start下面可以改动
|
|
33
|
+
|
|
34
|
+
stack = []
|
|
35
|
+
for digit in num:
|
|
36
|
+
while k and stack and stack[-1] > digit:
|
|
37
|
+
stack.pop()
|
|
38
|
+
k -= 1
|
|
39
|
+
stack.append(digit)
|
|
40
|
+
if k:
|
|
41
|
+
del stack[-k:]
|
|
42
|
+
lst_rlt = "".join(stack).lstrip("0") or "0"
|
|
43
|
+
|
|
44
|
+
##########end上面可以改动
|
|
45
|
+
return lst_rlt
|
|
46
|
+
|
|
47
|
+
if __name__ == "__main__":
|
|
48
|
+
###########下面可以修改
|
|
49
|
+
num = "1432219"
|
|
50
|
+
k = 3
|
|
51
|
+
print(TEST_DO_NOT_CHANGE( num,k))
|
|
52
|
+
# 题号:hwc511
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:复原IP地址
|
|
15
|
+
有效 IP 地址 正好由四个整数(每个整数位于 0 到 255 之间组成,且不能含有前导 0),整数之间用 '.' 分隔。
|
|
16
|
+
给定一个只包含数字的字符串 s ,用以表示一个 IP 地址,返回所有可能的有效 IP 地址,这些地址可以通过在 s 中插入 '.' 来形成。
|
|
17
|
+
|
|
18
|
+
注意:
|
|
19
|
+
1.你 不能 重新排序或删除 s 中的任何数字。
|
|
20
|
+
2.你可以按 任何 顺序返回答案。
|
|
21
|
+
|
|
22
|
+
例如:s = "101023"输出的结果为['1.0.10.23', '1.0.102.3', '10.1.0.23', '10.10.2.3', '101.0.2.3']
|
|
23
|
+
|
|
24
|
+
请分别复原以下几个字符串:
|
|
25
|
+
s1 = "25525511135"
|
|
26
|
+
s2 = "0000"
|
|
27
|
+
s3 = "192168101"
|
|
28
|
+
'''
|
|
29
|
+
|
|
30
|
+
# 参考答案
|
|
31
|
+
def TEST_DO_NOT_CHANGE(s):
|
|
32
|
+
print(s)
|
|
33
|
+
result = None
|
|
34
|
+
##########start下面可以改动
|
|
35
|
+
|
|
36
|
+
result = []
|
|
37
|
+
|
|
38
|
+
def search(start, parts):
|
|
39
|
+
remaining = 4 - len(parts)
|
|
40
|
+
if not remaining <= len(s) - start <= 3 * remaining:
|
|
41
|
+
return
|
|
42
|
+
if remaining == 0:
|
|
43
|
+
result.append(".".join(parts))
|
|
44
|
+
return
|
|
45
|
+
for end in range(start + 1, min(start + 3, len(s)) + 1):
|
|
46
|
+
part = s[start:end]
|
|
47
|
+
if (len(part) > 1 and part[0] == "0") or int(part) > 255:
|
|
48
|
+
break
|
|
49
|
+
search(end, parts + [part])
|
|
50
|
+
|
|
51
|
+
search(0, [])
|
|
52
|
+
|
|
53
|
+
##########end上面可以改动
|
|
54
|
+
return result
|
|
55
|
+
|
|
56
|
+
if __name__ == "__main__":
|
|
57
|
+
###########下面可以修改
|
|
58
|
+
s1 = "25525511135"
|
|
59
|
+
s2 = "0000"
|
|
60
|
+
s3 = "192168101"
|
|
61
|
+
print(TEST_DO_NOT_CHANGE(s1))
|
|
62
|
+
print(TEST_DO_NOT_CHANGE(s2))
|
|
63
|
+
print(TEST_DO_NOT_CHANGE(s3))
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:
|
|
15
|
+
被围绕的区域:给你一个 m x n 的矩阵 board,由若干字符 'X' 和 'O',
|
|
16
|
+
找到所有被 'X' 围绕的区域,并将这些区域里所有的 'O' 用 'X' 填充,最后返回修改后的 board。
|
|
17
|
+
|
|
18
|
+
示例 1:
|
|
19
|
+
输入: board = [["X","X","X","X"],
|
|
20
|
+
["X","O","O","X"],
|
|
21
|
+
["X","X","O","X"],
|
|
22
|
+
["X","O","X","X"]]
|
|
23
|
+
输出: [["X","X","X","X"],
|
|
24
|
+
["X","X","X","X"],
|
|
25
|
+
["X","X","X","X"],
|
|
26
|
+
["X","O","X","X"]]
|
|
27
|
+
解释: 被围绕的区间不会存在于边界上,换句话说,任何边界上的 'O' 都不会被填充为 'X'。
|
|
28
|
+
任何不在边界上,或不与边界上的 'O' 相连的 'O' 最终都会被填充为 'X'。
|
|
29
|
+
如果两个元素在水平或垂直方向相邻,则称它们是“相连”的。
|
|
30
|
+
|
|
31
|
+
示例 2:
|
|
32
|
+
输入: board = [["X"]]
|
|
33
|
+
输出: [["X"]]
|
|
34
|
+
|
|
35
|
+
示例 3:
|
|
36
|
+
输入: board = [['O', 'O'], ['O', 'O']]
|
|
37
|
+
输出: [['O', 'O'], ['O', 'O']]
|
|
38
|
+
'''
|
|
39
|
+
|
|
40
|
+
# 参考答案
|
|
41
|
+
def TEST_DO_NOT_CHANGE(board):
|
|
42
|
+
rlt = None
|
|
43
|
+
##########start下面可以改动
|
|
44
|
+
|
|
45
|
+
rlt = board
|
|
46
|
+
if not board or not board[0]:
|
|
47
|
+
return rlt
|
|
48
|
+
height, width = len(board), len(board[0])
|
|
49
|
+
stack = []
|
|
50
|
+
for row in range(height):
|
|
51
|
+
for col in range(width):
|
|
52
|
+
if (row in (0, height - 1) or col in (0, width - 1)) and board[row][col] == "O":
|
|
53
|
+
board[row][col] = "#"
|
|
54
|
+
stack.append((row, col))
|
|
55
|
+
while stack:
|
|
56
|
+
row, col = stack.pop()
|
|
57
|
+
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
|
|
58
|
+
nr, nc = row + dr, col + dc
|
|
59
|
+
if 0 <= nr < height and 0 <= nc < width and board[nr][nc] == "O":
|
|
60
|
+
board[nr][nc] = "#"
|
|
61
|
+
stack.append((nr, nc))
|
|
62
|
+
for row in range(height):
|
|
63
|
+
for col in range(width):
|
|
64
|
+
board[row][col] = "O" if board[row][col] == "#" else "X"
|
|
65
|
+
|
|
66
|
+
##########end上面可以改动
|
|
67
|
+
return rlt
|
|
68
|
+
|
|
69
|
+
if __name__ == "__main__":
|
|
70
|
+
###########下面可以修改
|
|
71
|
+
print(TEST_DO_NOT_CHANGE([["X","X","X","X"],["X","O","O","X"],["X","X","O","X"],["X","O","X","X"]]))
|
|
72
|
+
print(TEST_DO_NOT_CHANGE([["X"]]))
|
|
73
|
+
print(TEST_DO_NOT_CHANGE([["O","O"],["O","O"]]))
|
|
74
|
+
# 题号:hwc514
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:公共钥匙盒
|
|
15
|
+
|
|
16
|
+
有一个学校的老师共用N个教室,按照规定,所有的钥匙都必须放在公共钥匙盒里,老师不能带钥匙回家。
|
|
17
|
+
每次老师上课前,都从公共钥匙盒里找到自己上课的教室的钥匙去开门,上完课后,再将钥匙放回到钥匙盒中。
|
|
18
|
+
钥匙盒一共有N个挂钩,从左到右排成一排,用来挂N个教室的钥匙。
|
|
19
|
+
一串钥匙没有固定的悬挂位置,但钥匙上有标识,所以老师们不会弄混钥匙。
|
|
20
|
+
每次取钥匙的时候,老师们都会找到自己所需要的钥匙将其取走,而不会移动其他钥匙。
|
|
21
|
+
每次还钥匙的时候,还钥匙的老师会找到最左边的空的挂钩,将钥匙挂在这个挂钩上。
|
|
22
|
+
如果有多位老师还钥匙,则他们按钥匙编号从小到大的顺序还。
|
|
23
|
+
如果同一时刻既有老师还钥匙又有老师取钥匙,则老师们会先将钥匙全还回去再取出。
|
|
24
|
+
今天开始的时候钥匙是按编号从小到大的顺序放在钥匙盒里的。
|
|
25
|
+
有K位老师要上课,给出每位老师所需要的钥匙、开始上课的时间和上课的时长,假设下课时间就是还钥匙时间,
|
|
26
|
+
请问最终钥匙盒里面钥匙的顺序是怎样的?
|
|
27
|
+
|
|
28
|
+
列表 lst 的长度 K 即教师人数;lst 中每行三个整数 w, s, c,分别表示一位老师要使用的钥匙编号、开始上课的时间和上课的时长。
|
|
29
|
+
可能有多位老师使用同一把钥匙,但是老师使用钥匙的时间不会重叠。
|
|
30
|
+
|
|
31
|
+
输出格式
|
|
32
|
+
输出一行包含N个整数的列表,依次表示每个挂钩上挂的钥匙编号。
|
|
33
|
+
|
|
34
|
+
示例:
|
|
35
|
+
|
|
36
|
+
输入:N=5
|
|
37
|
+
lst=[[4,3,3],[2,2,7]]
|
|
38
|
+
输出:
|
|
39
|
+
[1,4,3,2,5]
|
|
40
|
+
解释:
|
|
41
|
+
共有5个挂钩,编号从1到5。
|
|
42
|
+
第一位老师从时刻3开始使用4号教室的钥匙,使用3单位时间,所以在时刻6还钥匙。
|
|
43
|
+
第二位老师从时刻2开始使用钥匙,使用7单位时间,所以在时刻9还钥匙。
|
|
44
|
+
每个关键时刻后的钥匙状态如下(X表示空):
|
|
45
|
+
时刻2后为1X345;
|
|
46
|
+
时刻3后为1X3X5;
|
|
47
|
+
时刻6后为143X5;
|
|
48
|
+
时刻9后为14325。
|
|
49
|
+
'''
|
|
50
|
+
|
|
51
|
+
# 参考答案
|
|
52
|
+
def TEST_DO_NOT_CHANGE(N, lst):
|
|
53
|
+
print(N, lst)
|
|
54
|
+
lst_rlt = []
|
|
55
|
+
##########start下面可以改动
|
|
56
|
+
|
|
57
|
+
from heapq import heappop, heappush
|
|
58
|
+
|
|
59
|
+
hooks = list(range(1, N + 1))
|
|
60
|
+
position = [-1] + list(range(N))
|
|
61
|
+
empty = []
|
|
62
|
+
events = []
|
|
63
|
+
for key, start, duration in lst:
|
|
64
|
+
events.append((start, 1, key))
|
|
65
|
+
events.append((start + duration, 0, key))
|
|
66
|
+
for _, taking, key in sorted(events):
|
|
67
|
+
if taking:
|
|
68
|
+
index = position[key]
|
|
69
|
+
hooks[index] = 0
|
|
70
|
+
heappush(empty, index)
|
|
71
|
+
else:
|
|
72
|
+
index = heappop(empty)
|
|
73
|
+
hooks[index] = key
|
|
74
|
+
position[key] = index
|
|
75
|
+
lst_rlt = hooks
|
|
76
|
+
|
|
77
|
+
##########end上面可以改动
|
|
78
|
+
return lst_rlt
|
|
79
|
+
|
|
80
|
+
if __name__ == "__main__":
|
|
81
|
+
###########下面可以修改
|
|
82
|
+
print(TEST_DO_NOT_CHANGE(5, [[4, 3, 3], [2, 2, 7]]))
|
|
83
|
+
print(TEST_DO_NOT_CHANGE(5, [[1, 1, 14], [3, 3, 12], [1, 15, 12], [2, 7, 20], [3, 18, 12], [4, 21, 19], [5, 30, 9]]))
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:计算水域大小
|
|
15
|
+
你有一个用于表示一片土地的整数矩阵land,该矩阵中每个点的值代表对应地点的海拔高度。若值为0则表示水域。
|
|
16
|
+
由垂直、水平或对角连接的水域为池塘。池塘的大小是指相连接的水域的个数。编写一个方法来计算矩阵中所有池塘的大小,
|
|
17
|
+
返回值需要从小到大排序。
|
|
18
|
+
|
|
19
|
+
示例:
|
|
20
|
+
|
|
21
|
+
输入:
|
|
22
|
+
[
|
|
23
|
+
[0,2,1,0],
|
|
24
|
+
[0,1,0,1],
|
|
25
|
+
[1,1,0,1],
|
|
26
|
+
[0,1,0,1]
|
|
27
|
+
]
|
|
28
|
+
输出: [1,2,4]
|
|
29
|
+
'''
|
|
30
|
+
|
|
31
|
+
# 参考答案
|
|
32
|
+
def TEST_DO_NOT_CHANGE(land):
|
|
33
|
+
lst_rlt = []
|
|
34
|
+
##########start下面可以改动
|
|
35
|
+
|
|
36
|
+
water = {
|
|
37
|
+
(row, col)
|
|
38
|
+
for row, cells in enumerate(land)
|
|
39
|
+
for col, value in enumerate(cells)
|
|
40
|
+
if value == 0
|
|
41
|
+
}
|
|
42
|
+
directions = [(dr, dc) for dr in (-1, 0, 1) for dc in (-1, 0, 1) if dr or dc]
|
|
43
|
+
while water:
|
|
44
|
+
stack = [water.pop()]
|
|
45
|
+
size = 0
|
|
46
|
+
while stack:
|
|
47
|
+
row, col = stack.pop()
|
|
48
|
+
size += 1
|
|
49
|
+
for dr, dc in directions:
|
|
50
|
+
neighbor = row + dr, col + dc
|
|
51
|
+
if neighbor in water:
|
|
52
|
+
water.remove(neighbor)
|
|
53
|
+
stack.append(neighbor)
|
|
54
|
+
lst_rlt.append(size)
|
|
55
|
+
lst_rlt.sort()
|
|
56
|
+
|
|
57
|
+
##########end上面可以改动
|
|
58
|
+
return lst_rlt
|
|
59
|
+
|
|
60
|
+
if __name__ == "__main__":
|
|
61
|
+
###########下面可以修改
|
|
62
|
+
print(TEST_DO_NOT_CHANGE([
|
|
63
|
+
[0, 2, 1, 0],
|
|
64
|
+
[0, 1, 0, 1],
|
|
65
|
+
[1, 1, 0, 1],
|
|
66
|
+
[0, 1, 0, 1]
|
|
67
|
+
]))
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
'''
|
|
3
|
+
请只在 "
|
|
4
|
+
##########start下面可以改动
|
|
5
|
+
|
|
6
|
+
##########end上面可以改动 "
|
|
7
|
+
|
|
8
|
+
中间部分作答,作答行数自由调整
|
|
9
|
+
|
|
10
|
+
请不要使用 input() 函数
|
|
11
|
+
|
|
12
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
13
|
+
|
|
14
|
+
题目:零钱兑换
|
|
15
|
+
给你一个整数数组coins,表示不同面额的硬币,以及一个整数amount,表示总金额。
|
|
16
|
+
计算并返回可以凑成总金额所需的最少的硬币个数。如果没有任何一种硬币组合能组成总金额,返回-1。
|
|
17
|
+
你可以认为每种硬币的数量是无限的。
|
|
18
|
+
重复的硬币面额按同一种面额处理;amount=0 时返回 0,无解时返回 -1。
|
|
19
|
+
|
|
20
|
+
示例:
|
|
21
|
+
输入:coins = [1, 2, 5], amount = 11
|
|
22
|
+
输出:3
|
|
23
|
+
'''
|
|
24
|
+
|
|
25
|
+
# 参考答案
|
|
26
|
+
|
|
27
|
+
def TEST_DO_NOT_CHANGE(coins, amount):
|
|
28
|
+
rlt = 0
|
|
29
|
+
##########start下面可以改动
|
|
30
|
+
|
|
31
|
+
unreachable = amount + 1
|
|
32
|
+
best = [0] + [unreachable] * amount
|
|
33
|
+
for coin in set(coins):
|
|
34
|
+
for value in range(coin, amount + 1):
|
|
35
|
+
best[value] = min(best[value], best[value - coin] + 1)
|
|
36
|
+
rlt = best[amount] if best[amount] != unreachable else -1
|
|
37
|
+
|
|
38
|
+
##########end上面可以改动
|
|
39
|
+
return rlt
|
|
40
|
+
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
###########下面可以修改
|
|
43
|
+
print(TEST_DO_NOT_CHANGE( [1,2,5],11))
|
|
44
|
+
print(TEST_DO_NOT_CHANGE([2],3)) # 无解,返回 -1
|
|
45
|
+
print(TEST_DO_NOT_CHANGE([1,2,5],0)) # 返回 0
|
|
46
|
+
print(TEST_DO_NOT_CHANGE([2,2,5],4)) # 重复面额按一种处理
|
|
@@ -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
|
+
给你一个未排序的整数数组 nums ,请你找出其中没有出现的最小的正整数。
|
|
16
|
+
|
|
17
|
+
示例 1:
|
|
18
|
+
输入:nums = [1,2,0]
|
|
19
|
+
输出:3
|
|
20
|
+
|
|
21
|
+
示例 2:
|
|
22
|
+
输入:nums = [3,4,-1,1]
|
|
23
|
+
输出:2
|
|
24
|
+
|
|
25
|
+
示例 3:
|
|
26
|
+
输入:nums = [7,8,9,11,12]
|
|
27
|
+
输出:10
|
|
28
|
+
|
|
29
|
+
本题采用标准的 First Missing Positive 定义:返回数组中没有出现的最小正整数。
|
|
30
|
+
|
|
31
|
+
'''
|
|
32
|
+
|
|
33
|
+
# 参考答案
|
|
34
|
+
|
|
35
|
+
def TEST_DO_NOT_CHANGE(nums):
|
|
36
|
+
print(nums)
|
|
37
|
+
rlt = None
|
|
38
|
+
##########start下面可以改动
|
|
39
|
+
|
|
40
|
+
# 按题干定义找最小正整数。原例 3 没有 1,因此正确结果是 1。
|
|
41
|
+
present = set(nums)
|
|
42
|
+
rlt = 1
|
|
43
|
+
while rlt in present:
|
|
44
|
+
rlt += 1
|
|
45
|
+
|
|
46
|
+
##########end上面可以改动
|
|
47
|
+
return rlt
|
|
48
|
+
|
|
49
|
+
if __name__ == "__main__":
|
|
50
|
+
###########下面可以修改
|
|
51
|
+
print(TEST_DO_NOT_CHANGE([1,2,0]))
|
|
52
|
+
print(TEST_DO_NOT_CHANGE([3,4,-1,1]))
|
|
53
|
+
print(TEST_DO_NOT_CHANGE([7,8,9,11,12]))
|
|
54
|
+
# 题号:hwc520
|
|
@@ -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
|
+
给你一个下标从 0 开始、长度为 n 的二进制字符串 s ,你可以对其执行两种操作:
|
|
17
|
+
1.选中一个下标 i 并且反转从下标 0 到下标 i(包括下标 0 和下标 i )的所有字符,成本为 i + 1 。
|
|
18
|
+
2.选中一个下标 i 并且反转从下标 i 到下标 n - 1(包括下标 i 和下标 n - 1 )的所有字符,成本为 n - i 。
|
|
19
|
+
返回使字符串内所有字符 相等 需要的 最小成本 。
|
|
20
|
+
|
|
21
|
+
反转 字符意味着:如果原来的值是 '0' ,则反转后值变为 '1' ,反之亦然。
|
|
22
|
+
|
|
23
|
+
示例 1:
|
|
24
|
+
|
|
25
|
+
输入:s = "0011"
|
|
26
|
+
输出:2
|
|
27
|
+
解释:执行第二种操作,选中下标 i = 2 ,可以得到 s = "0000" ,成本为 2 。可以证明 2 是使所有字符相等的最小成本。
|
|
28
|
+
|
|
29
|
+
示例 2:
|
|
30
|
+
|
|
31
|
+
输入:s = "010101"
|
|
32
|
+
输出:9
|
|
33
|
+
解释:执行第一种操作,选中下标 i = 2 ,可以得到 s = "101101" ,成本为 3 。
|
|
34
|
+
执行第一种操作,选中下标 i = 1 ,可以得到 s = "011101" ,成本为 2 。
|
|
35
|
+
执行第一种操作,选中下标 i = 0 ,可以得到 s = "111101" ,成本为 1 。
|
|
36
|
+
执行第二种操作,选中下标 i = 4 ,可以得到 s = "111110" ,成本为 2 。
|
|
37
|
+
执行第一种操作,选中下标 i = 5 ,可以得到 s = "111111" ,成本为 1 。
|
|
38
|
+
使所有字符相等的总成本等于 9 。可以证明 9 是使所有字符相等的最小成本。
|
|
39
|
+
'''
|
|
40
|
+
|
|
41
|
+
# 参考答案
|
|
42
|
+
def TEST_DO_NOT_CHANGE(s):
|
|
43
|
+
result = None
|
|
44
|
+
##########start下面可以改动
|
|
45
|
+
|
|
46
|
+
# 每个不相等的相邻边界都必须翻转一次。
|
|
47
|
+
# 只改变该边界的两种操作分别是翻转左前缀与翻转右后缀。
|
|
48
|
+
n = len(s)
|
|
49
|
+
result = sum(min(i, n - i) for i in range(1, n) if s[i - 1] != s[i])
|
|
50
|
+
|
|
51
|
+
##########end上面可以改动
|
|
52
|
+
return result
|
|
53
|
+
|
|
54
|
+
if __name__ == "__main__":
|
|
55
|
+
###########下面可以修改
|
|
56
|
+
print(TEST_DO_NOT_CHANGE("0011"))
|
|
57
|
+
print(TEST_DO_NOT_CHANGE("010101"))
|
|
58
|
+
# 题号:hwc526
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
请只在 "
|
|
2
|
+
##########start下面可以改动
|
|
3
|
+
|
|
4
|
+
##########end上面可以改动 "
|
|
5
|
+
|
|
6
|
+
中间部分作答,作答行数自由调整
|
|
7
|
+
|
|
8
|
+
请不要使用 input() 函数
|
|
9
|
+
|
|
10
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
11
|
+
|
|
12
|
+
题目:
|
|
13
|
+
给定一个按升序排列(从小到大)的数组和一个目标值,在数组中找到目标值,并返回其索引(下标,从 0 开始数)。
|
|
14
|
+
如果目标值不存在于数组中,返回它应该插入的位置(插进去之后数组仍然保持升序)。
|
|
15
|
+
你可以假设数组中无重复元素。
|
|
16
|
+
|
|
17
|
+
示例 1:
|
|
18
|
+
输入: [1,3,5,6], 5
|
|
19
|
+
输出: 2
|
|
20
|
+
|
|
21
|
+
示例2:
|
|
22
|
+
输入: [1,3,5,6], 2
|
|
23
|
+
输出: 1
|
|
24
|
+
|
|
25
|
+
示例 3:
|
|
26
|
+
输入: [1,3,5,6], 7
|
|
27
|
+
输出: 4
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
请只在 "
|
|
2
|
+
##########start下面可以改动
|
|
3
|
+
|
|
4
|
+
##########end上面可以改动 "
|
|
5
|
+
|
|
6
|
+
中间部分作答,作答行数自由调整
|
|
7
|
+
|
|
8
|
+
请不要使用 input() 函数
|
|
9
|
+
|
|
10
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
11
|
+
|
|
12
|
+
题目:
|
|
13
|
+
给你一个字符串 s,由若干单词组成,单词之间用空格隔开。返回字符串中最后一个单词的长度。如果不存在最后一个单词,请返回 0。
|
|
14
|
+
单词 是指仅由字母组成、不包含任何空格字符的最大子字符串。
|
|
15
|
+
|
|
16
|
+
示例 1:
|
|
17
|
+
输入:s = "Hello World"
|
|
18
|
+
输出:5
|
|
19
|
+
|
|
20
|
+
示例 2:
|
|
21
|
+
输入:s = " "
|
|
22
|
+
输出:0
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
请只在 "
|
|
2
|
+
##########start下面可以改动
|
|
3
|
+
|
|
4
|
+
##########end上面可以改动 "
|
|
5
|
+
|
|
6
|
+
中间部分作答,作答行数自由调整
|
|
7
|
+
|
|
8
|
+
请不要使用 input() 函数
|
|
9
|
+
|
|
10
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
11
|
+
|
|
12
|
+
题目:
|
|
13
|
+
给定一个整数 n,返回 n! 结果尾数中零的数量。
|
|
14
|
+
|
|
15
|
+
示例 1:
|
|
16
|
+
输入: 3
|
|
17
|
+
输出: 0
|
|
18
|
+
解释:3! = 6, 尾数中没有零。
|
|
19
|
+
|
|
20
|
+
示例2:
|
|
21
|
+
输入: 5
|
|
22
|
+
输出: 1
|
|
23
|
+
解释:5! = 120, 尾数中有 1 个零.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
请只在 "
|
|
2
|
+
##########start下面可以改动
|
|
3
|
+
|
|
4
|
+
##########end上面可以改动 "
|
|
5
|
+
|
|
6
|
+
中间部分作答,作答行数自由调整
|
|
7
|
+
|
|
8
|
+
请不要使用 input() 函数
|
|
9
|
+
|
|
10
|
+
此题在期中考试考察范围内,作业需提交,注意期中考试有卷面分,请认真作答。
|
|
11
|
+
|
|
12
|
+
题目
|
|
13
|
+
给定一个整数数组,判断是否存在重复元素。
|
|
14
|
+
如果存在一值在数组中出现至少两次,函数返回 True 。如果数组中每个元素都不相同,则返回 False 。
|
|
15
|
+
|
|
16
|
+
示例 1:
|
|
17
|
+
输入: [1,2,3,1]
|
|
18
|
+
输出: True
|
|
19
|
+
|
|
20
|
+
示例 2:
|
|
21
|
+
输入: [1,2,3,4]
|
|
22
|
+
输出: False
|
|
23
|
+
|
|
24
|
+
示例3:
|
|
25
|
+
输入: [1,1,1,3,3,4,3,2,4,2]
|
|
26
|
+
输出: True
|