Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb3bfeff

Browse files
committed
Update to 048
Update to 048
1 parentcb7dd50 commitb3bfeff

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

‎Python3/046_Permutations.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ def permute(self, nums):
1919
self.get_permute([],nums,result)
2020
returnresult
2121

22-
defget_permute(self,current,num,result):
23-
ifnotnum:
22+
defget_permute(self,current,nums,result):
23+
ifnotnums:
2424
result.append(current+ [])
2525
return
26-
fori,vinenumerate(num):
27-
current.append(num[i])
28-
self.get_permute(current,num[:i]+num[i+1:],result)
29-
current.pop()
26+
else:
27+
fori,vinenumerate(nums):
28+
current.append(nums[i])
29+
self.get_permute(current,nums[:i]+nums[i+1:],result)
30+
current.pop()
3031

3132

3233
if__name__=="__main__":

‎Python3/048_Rotate Image.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!usr/bin/env python3
2+
# -*- coding:utf-8 -*-
3+
'''
4+
You are given an n x n 2D matrix representing an image.
5+
6+
Rotate the image by 90 degrees (clockwise).
7+
8+
Follow up:
9+
Could you do this in-place?
10+
'''
11+
12+
13+
classSolution(object):
14+
defrotate(self,matrix):
15+
"""
16+
:type matrix: List[List[int]]
17+
:rtype: void Do not return anything, modify matrix in-place instead.
18+
"""
19+
n=len(matrix)
20+
foriinrange(n):
21+
forjinrange(i+1,n):
22+
matrix[i][j],matrix[j][i]=matrix[j][i],matrix[i][j]
23+
foriinrange(n):
24+
matrix[i].reverse()
25+
returnmatrix
26+
27+
if__name__=="__main__":
28+
assertSolution().rotate([[1,2,3], [8,9,4], [7,6,5]])== [[7,8,1], [6,9,2], [5,4,3]]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp