We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 12d6e1f commit c098a4eCopy full SHA for c098a4e
LeetCode SQL 50 Solution/626. Exchange Seats/626. Exchange Seats.py
@@ -0,0 +1,18 @@
1
+import pandas as pd
2
+
3
+def exchange_seats(seat: pd.DataFrame) -> pd.DataFrame:
4
+ # Total number of students
5
+ total = seat.shape[0]
6
7
+ # Function to compute the new seat id
8
+ def new_id(row):
9
+ # For odd id values:
10
+ if row['id'] % 2 != 0:
11
+ # If it's the last row in an odd-length list, do not change the id.
12
+ if row['id'] == total:
13
+ return row['id']
14
+ else:
15
+ return row['id'] + 1
16
+ # For even id values, swap with previous odd id
17
18
+ return row['id'] - 1
0 commit comments