Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Python Tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
python-version: [3.8, 3.9]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Run tests
run: |
python -m unittest discover
4 changes: 4 additions & 0 deletions ProblemsByTags.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"ThreeSum",
"TopKFrequentNums"
],
"Extreme": [
"FirstMissingPositive"
],
"Hard": [
"Codec",
"LongestPalindrome",
Expand Down Expand Up @@ -49,6 +52,7 @@
"ThreeSum"
],
"Sorting": [
"FirstMissingPositive",
"SortColors"
],
"Strings": [
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Please make sure to replace everything need to be replaced.

Add a few test cases, make sure they're running smoothly.

Run `.\build.ps1`.
Run `python ProblemsByTags.py`.
If everything is OK, push it and open a PR.

## Troubleshooting
Expand Down
55 changes: 55 additions & 0 deletions Solutions/F/FirstMissingPositive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import unittest
from Tags import *

"""
Author: Jonathan Joseph
Problem Description/link: replace with relevant link or problem description
"""


class Solution(object):
def getTags(self):
tags = [Difficulty.Extreme, Topic.Sorting]
return tags

def firstMissingPositive(self, nums):
"""
:type nums: List[int]
:rtype: int
"""

if not nums:
return 1

ptr = 0
junk = len(nums)

while ptr < junk:
if nums[ptr] == ptr + 1:
ptr += 1
continue

if nums[ptr] <= 0 or nums[ptr] >= junk or nums[ptr] == nums[nums[ptr] - 1]:
junk -= 1
nums[ptr], nums[junk] = nums[junk], nums[ptr]
continue

temp = nums[nums[ptr] - 1]
nums[nums[ptr] - 1] = nums[ptr]
nums[ptr] = temp

for i in range(len(nums)):
if nums[i] != i + 1:
return i + 1

return len(nums) + 1


class test_firstMissingPositive(unittest.TestCase):
def test_1(self):
self.assertEqual(2, Solution().firstMissingPositive([3, 3, 1, 4, 0]))
self.assertEqual(1, Solution().firstMissingPositive([3, -7, 2, 4, 0]))
self.assertEqual(6, Solution().firstMissingPositive([1, 2, 3, 5, 4]))
self.assertEqual(1, Solution().firstMissingPositive([-7]))
self.assertEqual(1, Solution().firstMissingPositive([]))
self.assertEqual(2, Solution().firstMissingPositive([1, 1, 1, 1, 1, 1, 1, 1]))
Empty file added Solutions/F/__init__.py
Empty file.
50 changes: 50 additions & 0 deletions Solutions/Z/ZigzagConversion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import unittest
from Tags import *
"""
Author: Jonathan Joseph
Problem Description/link: replace with relevant link or problem description
"""

class Solution(object):
def getTags(self):
tags = [Difficulty.Hard, Topic.Strings]
return tags

def convert(self, s, numRows):
"""
:type s: str
:type numRows: int
:rtype: str
"""
if numRows == 1:
return s

res = ''
delta = (2*(numRows-1))

for r in range(numRows):
if r == 0 or r == numRows - 1:
i = r
while i < len(s):
res += s[i]
i += delta

else:
indices = [r, delta-r]
i = 0
while indices[i] < len(s):
res += s[indices[i]]
indices[i] += delta
i = ((i+1) % len(indices))

return res



class test_zigzagConversion(unittest.TestCase):
def test_1(self):
self.assertEqual(Solution().convert("PAYPALISHIRING", 3), "PAHNAPLSIIGYIR")
self.assertEqual(Solution().convert("PAYPALISHIRING", 4), "PINALSIGYAHRPI")
self.assertEqual(Solution().convert("PAYPALISHIRING", 1), "PAYPALISHIRING")
self.assertEqual(Solution().convert("ABCD", 3), "ABDC")
self.assertEqual(Solution().convert("a", 7), "a")
Empty file added Solutions/Z/__init__.py
Empty file.