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

Appearance settings

Commit b3bfeff

Browse filesBrowse files
committed
Update to 048
Update to 048
1 parent cb7dd50 commit b3bfeff
Copy full SHA for b3bfeff

File tree

2 files changed

+35
-6
lines changed
Filter options

2 files changed

+35
-6
lines changed

‎Python3/046_Permutations.py

Copy file name to clipboardExpand all lines: Python3/046_Permutations.py
+7-6Lines 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
return result
2121

22-
def get_permute(self, current, num, result):
23-
if not num:
22+
def get_permute(self, current, nums, result):
23+
if not nums:
2424
result.append(current + [])
2525
return
26-
for i, v in enumerate(num):
27-
current.append(num[i])
28-
self.get_permute(current, num[:i] + num[i + 1:], result)
29-
current.pop()
26+
else:
27+
for i, v in enumerate(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

Copy file name to clipboard
+28Lines 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+
class Solution(object):
14+
def rotate(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+
for i in range(n):
21+
for j in range(i + 1, n):
22+
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
23+
for i in range(n):
24+
matrix[i].reverse()
25+
return matrix
26+
27+
if __name__ == "__main__":
28+
assert Solution().rotate([[1, 2, 3], [8, 9, 4], [7, 6, 5]]) == [[7, 8, 1], [6, 9, 2], [5, 4, 3]]

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.