diff --git a/Find all numbers disappeared in Array.py b/Find all numbers disappeared in Array.py new file mode 100644 index 00000000..05b72bca --- /dev/null +++ b/Find all numbers disappeared in Array.py @@ -0,0 +1,14 @@ +class Solution: + def findDisappearedNumbers(self, nums: List[int]) -> List[int]: + n=len(nums) + result=[] + for i in range(len(nums)): + if nums[abs(nums[i])-1]>0: + nums[abs(nums[i])-1]=nums[abs(nums[i])-1]*-1 + + for i in range(len(nums)): + if nums[i]>0: + result.append(i+1) + else: + nums[i]=nums[i]*-1 + return result \ No newline at end of file diff --git a/Game of Life.py b/Game of Life.py new file mode 100644 index 00000000..9c7fc8f5 --- /dev/null +++ b/Game of Life.py @@ -0,0 +1,39 @@ +class Solution: + def gameOfLife(self, board: List[List[int]]) -> None: + """ + Do not return anything, modify board in-place instead. + """ + m=len(board) + n=len(board[0]) + + #1-0 ->2 + #0-1-> 3 + for i in range(m): + for j in range(n): + countn=self.neighbourCount(board, i , j) + if board[i][j]==1: + if countn<2 or countn>3: + board[i][j]=2 + + else: + if countn==3: + board[i][j]=3 + for i in range(m): + for j in range(n): + if board[i][j]==2: + board[i][j]=0 + elif board[i][j]==3: + board[i][j]=1 + def neighbourCount( self,board: List[List[int]], r: int, c:int)->int: + count=0 + m=len(board) + n=len(board[0]) + + dirr=[[-1,-1],[-1,0],[-1,1],[0,1],[1,1],[1,0],[1,-1],[0,-1]] + for dir in dirr: + nr=r+dir[0] + nc=c+dir[1] + + if nr>=0 and nc>=0 and nr