題目1
旋轉陣列
給定乙個陣列,將陣列中的元素向右移動 k 個位置,其中 k 是非負數。
示例 1:
輸入:示例 2:[1,2,3,4,5,6,7]
和 k = 3輸出:
[5,6,7,1,2,3,4]
解釋:向右旋轉 1 步:
[7,1,2,3,4,5,6]
向右旋轉 2 步:[6,7,1,2,3,4,5]
向右旋轉 3 步:[5,6,7,1,2,3,4]
輸入:說明:[-1,-100,3,99]
和 k = 2輸出: [3,99,-1,-100]
解釋:
向右旋轉 1 步: [99,-1,-100,3]
向右旋轉 2 步: [3,99,-1,-100]
致謝:特別感謝 @freezen 新增此問題並建立所有測試用例。
python
classsolution(object):
defrotate(self, nums, k):
"""
:type nums: list[int]
:type k: int
:rtype: void do not return anything, modify nums in-place instead.
"""
t = k
whilet>
0:
temp = nums.pop()
nums.insert(0, temp)
t -= 1
第九周作業 1
includeusing namespace std class complex complex double r,double i complex operator complex c2 complex operator complex c2 complex operator complex c2...
第九周作業
1 編寫指令碼,接受二個位置引數,magedu和 www,判斷系統是否有magedu,如果沒有則自動建立magedu使用者,並自動設定家目錄為 www vim create user.sh bin bash if ne 2 then echo 0 username directory exit 1 ...
第九周作業
cat data canshu.sh bin bash user 1 dir 2if 2 then echo 請輸入兩個引數 exit else id dev null if 0 then mkdir dev null useradd d dev null echo 使用者 建立成功 else ec...