You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
id is the primary key (unique value) column for this table.
11
+
Each row of this table indicates the name and the ID of a student.
12
+
The ID sequence always starts from 1 and increments continuously.
13
+
</pre>
14
+
15
+
<p> </p>
16
+
17
+
<p>Write a solution to swap the seat id of every two consecutive students. If the number of students is odd, the id of the last student is not swapped.</p>
18
+
19
+
<p>Return the result table ordered by <code>id</code> <strong>in ascending order</strong>.</p>
20
+
21
+
<p>The result format is in the following example.</p>
22
+
23
+
<p> </p>
24
+
<p><strongclass="example">Example 1:</strong></p>
25
+
26
+
<pre>
27
+
<strong>Input:</strong>
28
+
Seat table:
29
+
+----+---------+
30
+
| id | student |
31
+
+----+---------+
32
+
| 1 | Abbot |
33
+
| 2 | Doris |
34
+
| 3 | Emerson |
35
+
| 4 | Green |
36
+
| 5 | Jeames |
37
+
+----+---------+
38
+
<strong>Output:</strong>
39
+
+----+---------+
40
+
| id | student |
41
+
+----+---------+
42
+
| 1 | Doris |
43
+
| 2 | Abbot |
44
+
| 3 | Green |
45
+
| 4 | Emerson |
46
+
| 5 | Jeames |
47
+
+----+---------+
48
+
<strong>Explanation:</strong>
49
+
Note that if the number of students is odd, there is no need to change the last one's seat.
0 commit comments