diff --git a/Problem-1.py b/Problem-1.py new file mode 100644 index 00000000..4f604be2 --- /dev/null +++ b/Problem-1.py @@ -0,0 +1,38 @@ +#Pascal's Triangle +# Time Complexity :O(n2) +# Space Complexity :O(1) +# Did this code successfully run on Leetcode :yes +# Any problem you faced while coding this :no + + +# Your code here along with comments explaining your approach +#start with first row of pascal triangle as [1] and then iterate through numsRows and keep adding arrays to result array by adding sum of the two numbers directly above and also parallely checking the two edges of each row +#time - O(n2) +#space - O(1) + +class Solution: + def generate(self, numRows: int) -> List[List[int]]: + result = [[]] + if(numRows==0): + return result + result = [[1]] + i=2 + while(i<=numRows): + p1=0 + p2=1 + curr=[] + j=0 + while(j int: + hashMap = Counter(nums) # frequency map + count=0 + for key, value in hashMap.items(): + if k==0: + if value>1: + count =count+1 + continue + if key+k in hashMap: + count=count+1 + return count + + + \ No newline at end of file