This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution: | |
| def rotate(self, matrix: List[List[int]]) -> None: | |
| matrix[:]=zip(*matrix[::-1]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def reverseArray(nums, m): | |
| n=len(nums) | |
| nums=nums[0:m+1]+nums[n:m:-1] | |
| return nums |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution: | |
| def maxProfit(self, prices: List[int]) -> int: | |
| current_min, max_so_far = prices[0], 0 | |
| for price in prices: | |
| current_min = min(current_min, price) | |
| max_so_far = max(max_so_far, price-current_min) | |
| return max_so_far | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution: | |
| def sortColors(self, nums: List[int]) -> None: | |
| nums.sort() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution: | |
| def maxSubArray(self, nums: List[int]) -> int: | |
| sumUpToIdx = 0 | |
| maxSum = nums[0] | |
| for num in nums: | |
| sumUpToIdx += num | |
| if sumUpToIdx < num: | |
| sumUpToIdx = num | |
| if maxSum < sumUpToIdx: | |
| maxSum = sumUpToIdx |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution: | |
| def nextPermutation(self, nums: List[int]) -> None: | |
| """ | |
| Do not return anything, modify nums in-place instead. | |
| """ | |
| n = len(nums) | |
| p1 = -1 | |
| for i in range(n-1): | |
| if nums[i]<nums[i+1]: | |
| p1 = i |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution: | |
| def generate(self, numRows: int) -> List[List[int]]: | |
| solution=[[1]] | |
| for i in range(1, numRows, 1): | |
| solution.append([comb(i, j) for j in range(0, i+1, 1)]) | |
| return solution |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Solution: | |
| def setZeroes(self, matrix: List[List[int]]) -> None: | |
| row=len(matrix) | |
| col=len(matrix[0]) | |
| col1=1 | |
| for i in range(row): | |
| if matrix[i][0]==0: | |
| col1=0 | |
| for j in range(1,col): | |
| if matrix[i][j]==0: |