Ai
1 Star 0 Fork 2

open/Python-100-Days

forked from 阿甘/Python-100-Days 
Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
This repository doesn't specify license. Please pay attention to the specific project description and its upstream code dependency when using it.
Clone or Download
homework02.py 1.21 KB
Copy Edit Raw Blame History
jackfrued authored 2019-02-13 07:38 +08:00 . 更新了文档和目录结构
"""
模拟面试编程题
"""
def second_max(items: list, gt=lambda x, y: x > y):
"""从列表中找出第二大元素"""
assert len(items) >= 2
max1, max2 = (items[0], items[1]) \
if gt(items[0], items[1]) else (items[1], items[0])
for i in range(2, len(items)):
if gt(max1, items[i]) and gt(items[i], max2):
max2 = items[i]
elif gt(items[i], max1):
max1, max2 = items[i], max1
return max2
def list_depth(items: list) -> int:
"""计算嵌套列表的嵌套深度"""
if isinstance(items, list):
max_depth = 1
for item in items:
max_depth = max(list_depth(item) + 1, max_depth)
return max_depth
return 0
def main():
"""主函数"""
one_set = {1}
pos, off = 1, 1
while pos <= 100000000:
pos += off
one_set.add(pos)
off += 1
num, *poses = map(int, input().split())
for pos in poses:
print(1 if pos in one_set else 0, end=' ')
# items1 = [38, 95, 27, 95, 88, 73, 61, 50]
# print(second_max(items1))
# items2 = [[1], [[[2]]],[[3]], 4, [[[[[5, [6]]]]]]]
# print(list_depth(items1))
# print(list_depth(items2))
if __name__ == '__main__':
main()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
HTML
1
https://gitee.com/netb/Python-100-Days.git
git@gitee.com:netb/Python-100-Days.git
netb
Python-100-Days
Python-100-Days
master

Search