Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4dd0e2b

Browse files
improve performance
1 parent 1fc816e commit 4dd0e2b

File tree

3 files changed

+53
-59
lines changed

3 files changed

+53
-59
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import sys
2+
3+
def main():
4+
n = int(input())
5+
if not(n >= 2 and n <= (2*10**5) ):
6+
sys.exit(1)
7+
8+
numbers = input().split()
9+
numbers = [int(each) for each in numbers]
10+
11+
total_s = n * (n + 1) / 2
12+
print(int(total_s-sum(numbers)))
13+
14+
15+
if __name__ == "__main__":
16+
main()
Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
1-
Missing Number
2-
3-
You are given all numbers between 1,2,...,n except one. Your task is to find the missing number.
4-
5-
Input
6-
7-
The first input line contains an integer n.
8-
9-
The second line contains n−1 numbers. Each number is distinct and between 1 and n (inclusive).
10-
11-
Output
12-
13-
Print the missing number.
14-
15-
Constraints
16-
2≤n≤2⋅105
17-
Example
18-
19-
Input:
20-
5
21-
2 3 1 5
22-
23-
Output:
24-
4
25-
26-
---
27-
---
28-
29-
شما تمام اعداد بین 1,2,....,n را دارید به غیر از یکی. وظیفه شما پیدا کردن عدد گم شده است.
30-
31-
مثال :
32-
33-
ورودی :
34-
5
35-
2 3 1 5
36-
37-
خروجی :
1+
Missing Number
2+
3+
You are given all numbers between 1,2,...,n except one. Your task is to find the missing number.
4+
5+
Input
6+
7+
The first input line contains an integer n.
8+
9+
The second line contains n−1 numbers. Each number is distinct and between 1 and n (inclusive).
10+
11+
Output
12+
13+
Print the missing number.
14+
15+
Constraints
16+
2≤n≤2⋅105
17+
Example
18+
19+
Input:
20+
5
21+
2 3 1 5
22+
23+
Output:
24+
4
25+
26+
---
27+
---
28+
29+
شما تمام اعداد بین 1,2,....,n را دارید به غیر از یکی. وظیفه شما پیدا کردن عدد گم شده است.
30+
31+
مثال :
32+
33+
ورودی :
34+
5
35+
2 3 1 5
36+
37+
خروجی :
3838
4

‎Medium-Questions/16-Missing_Number/Python/sixteen.py‎

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /