diff --git a/Diagnol Traverse.py b/Diagnol Traverse.py new file mode 100644 index 00000000..322b0e3e --- /dev/null +++ b/Diagnol Traverse.py @@ -0,0 +1,36 @@ +class Solution: + def findDiagonalOrder(self, mat: List[List[int]]) -> List[int]: + m=len(mat) + n=len(mat[0]) + + result=[0 for i in range(m*n)] + + index=0 + r=0 + c=0 + dirr=1 + + while index List[int]: + n=len(nums) + + result=[0 for i in range(n)] + result[0]=1 + rp=1 + for i in range(1,n): + rp=rp*nums[i-1] + result[i]=rp + print(result) + rp=1 + for i in range(n-2,-1,-1): + rp=rp*nums[i+1] + result[i]=rp*result[i] + return result \ No newline at end of file diff --git a/Spiral Matrix.py b/Spiral Matrix.py new file mode 100644 index 00000000..4fd78306 --- /dev/null +++ b/Spiral Matrix.py @@ -0,0 +1,33 @@ + +class Solution: + def spiralOrder(self, matrix: List[List[int]]) -> List[int]: + if matrix == None or len(matrix) ==0: + return [] + m= len(matrix) + n= len(matrix[0]) + result=[] + top=0 + bottom= m-1 + left =0 + right =n-1 + + while top<=bottom and left<=right: + if top<=bottom and left<=right: + for i in range(left, right+1): + result.append(matrix[top][i]) + top = top+1 + if top<=bottom and left<=right: + for i in range(top , bottom+1): + result.append(matrix[i][right]) + right = right-1 + if top<=bottom and left<=right: + for i in range(right, left-1,-1): + result.append(matrix[bottom][i]) + bottom = bottom-1 + if top<=bottom and left<=right: + for i in range(bottom, top-1,-1): + result.append(matrix[i][left]) + left=left+1 + + + return result \ No newline at end of file