Skip to content

Commit

Permalink
Adds sorting example
Browse files Browse the repository at this point in the history
  • Loading branch information
joffilyfe committed Dec 29, 2023
1 parent 8595092 commit 645085e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions 977.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# https://leetcode.com/problems/squares-of-a-sorted-array/

from typing import List
import unittest


class Solution:
def sortedSquares(self, nums: List[int]) -> List[int]:
return sorted([n**2 for n in nums])


class Test(unittest.TestCase):
def setUp(self):
self.solution = Solution()

def test_first(self):
self.assertEqual(
self.solution.sortedSquares(nums=[-4, -1, 0, 3, 10]), [0, 1, 9, 16, 100]
)

def test_second(self):
self.assertEqual(
self.solution.sortedSquares(nums=[-7, -3, 2, 3, 11]), [4, 9, 9, 49, 121]
)


if __name__ == "__main__":
unittest.main()
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
| Problem Number | Tag | URL |
| -------------- | ---------------------- | -------------------------------------------------------------------------- |
| 1.py | Hash table | https://leetcode.com/problems/two-sum/ |
| 977.py | Sorting | https://leetcode.com/problems/squares-of-a-sorted-array/ |
| 1051.py | | |
| 1207.py | | |
| 1337.py | Heap | https://leetcode.com/problems/the-k-weakest-rows-in-a-matrix |
Expand Down

0 comments on commit 645085e

Please sign in to comment.