[英]Find second maximum number in a list - HackerRank — Python
I am just trying To solve Find second maximum number in a list problem on HackerRank.我只是想解决在 HackerRank 上的列表问题中查找第二个最大数。
Here is my code:这是我的代码:
lst = []
n = int(input(""))
arr3=[]
for i in range(0, n):
ele = int(input())
lst.append(ele)
for i in lst:
if(i not in arr3):
arr3.append(i)
arr3.sort()
x=len(arr3)
print(arr3[x-2])
when i run the program on VScode IDE it runs fine, but when i test in HackerRank builtin IDE it return message as Runtime error stating ValueError: invalid literal for int() with base 10
当我在 VScode IDE 上运行程序时,它运行良好,但是当我在 HackerRank 内置 IDE 中测试时,它返回消息作为运行时错误,说明
ValueError: invalid literal for int() with base 10
Referencing the problem: Second Max in a List参考问题: 列表中的第二个最大值
if __name__ == '__main__':
n = int(input())
arr = map(int, input().split())
my_array = list(arr)
print(
max([x for x in my_array if x != max(my_array)])
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.