Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
22 changes: 22 additions & 0 deletions longest-substring-without-repeating-characters/naringst.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

# Runtime: 51ms, Memory: 16.83MB
# Time complexity: O(len(s))
# Space complexity: O(len(s))

class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
stringArr = []
maxLength = 0

for sub in s :
if sub in stringArr :
maxLength = max(maxLength, len(stringArr))
repeatIdx = stringArr.index(sub)
stringArr = stringArr[repeatIdx+1 :]

stringArr.append(sub)

maxLength = max(maxLength, len(stringArr))


return maxLength
44 changes: 44 additions & 0 deletions number-of-islands/naringst.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from collections import deque

# Runtime: 241ms, Memory: 18.94MB
# Time complexity: O(len(n*m))
# Space complexity: O(len(n*m))


class Solution:
def bfs(self, a,b, grid, visited) :
n = len(grid)
m = len(grid[0])

dx = [0, 0, 1, -1]
dy = [1, -1 ,0 ,0]
q = deque()
q.append([a,b])
visited[a][b] = True

while q :
x,y = q.popleft()

for i in range(4) :
nx = x + dx[i]
ny = y + dy[i]

if (0 <= nx < n and 0 <= ny < m and not visited[nx][ny] and grid[nx][ny] == '1'):
visited[nx][ny] = True
q.append([nx,ny])



def numIslands(self, grid: List[List[str]]) -> int:
n = len(grid)
m = len(grid[0])
visited = [[False] * m for _ in range(n)]
answer = 0

for i in range(n) :
for j in range(m) :
if grid[i][j] == '1' and not visited[i][j] :
self.bfs(i,j,grid,visited)
answer += 1

return answer
27 changes: 27 additions & 0 deletions reverse-linked-list/naringst.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

# Runtime: 39ms, Memory: 17.88MB
# Time complexity: O(len(head))
# Space complexity: O(len(head))


# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next

class Solution:
def __init__(self):
self.nodes = [] # ListNode 객체를 저장할 배열

def reverseList(self, head: Optional[ListNode]) -> List[Optional[ListNode]]:
prev = None
curr = head

while curr is not None:
nextNode = curr.next
curr.next = prev
prev = curr
curr = nextNode

return prev