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

Commit 6b5dee2

Browse files
committed
Add code for leetcode 977 and update README.md.
1 parent d004d08 commit 6b5dee2

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

‎README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Python 玩转 LeetCode 的学习之路
2323

2424
- [LeetCode面试系列 第10天:No.976 - 三角形的最大周长](http://www.justdopython.com/2019/11/20/leetcode976-largest-perimeter-triangle/)
2525

26+
- [LeetCode面试系列 第12天:No.977 - 有序数组的平方](http://www.justdopython.com/2019/11/25/python-leetcode977-squares-of-a-sorted-array/)
27+
28+
- [LeetCode面试系列 第11天:No.645 - 错误的集合](http://www.justdopython.com/2019/11/25/python-leetcode645-set-mismatch/)
29+
2630

2731
关注公众号:python技术,回复"python"一起学习交流
2832

‎leetcode-977/leetcode977.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from typing import List
2+
3+
class Solution:
4+
def sortedSquares(self, A: List[int]) -> List[int]:
5+
B = sorted(A, key = abs) # sort by absolute values
6+
res = list()
7+
for elem in B:
8+
res.append(elem*elem)
9+
return res
10+
11+
# below is testing
12+
sol = Solution()
13+
print(sol.sortedSquares([-4,-2, 3,6]))

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /