LeetCode.626. 換座位

思路: 檢索每一個id值,如果爲奇數則設爲i+1,如果是偶數則設爲i-1,注意末位是奇是偶,重新輸出即可。 代碼: select if(id<(select count(*) from seat),if(id%2=0,id-1,id+1),if(id%2=0,id-1,id)) as id,student from seat order by id;
相關文章
相關標籤/搜索