下面记录一下我遇到的一些找规律的问题
0X00 总结
from math import sqrt
class Solution:
def bulbSwitch(self, n: int) -> int:
return int(sqrt(n))
class Solution:
def convert(self, s: str, numRows: int) -> str:
if not s or numRows <= 1: return s
temp = [[] for _ in range(numRows) ]
dirs = 1
index = 0
for c in s:
temp[index].append(c)
index += dirs
if index == 0 or index == numRows-1:
dirs *= -1
ans = []
for line in temp:
ans += line
return "".join(ans)
class Solution:
def rotate(self, matrix: List[List[int]]) -> None:
"""
Do not return anything, modify matrix in-place instead.
"""
# 先翻转
# 在沿正对角线交换元素
if len(matrix) == 0: return
m, n = len(matrix), len(matrix[0])
matrix[:] = matrix[::-1]
for x in range(m):
for y in range(x+1, n):
matrix[x][y], matrix[y][x] = matrix[y][x], matrix[x][y]
网友评论