File tree Expand file tree Collapse file tree 6 files changed +102
-3
lines changed
Expand file tree Collapse file tree 6 files changed +102
-3
lines changed Original file line number Diff line number Diff line change 1+ from typing import List
2+
3+
4+ class Solution :
5+ def summaryRanges (self , nums : List [int ]) -> List [str ]:
6+ if not nums : # check for empty list
7+ return []
8+ res = []
9+ l = 0
10+ for r in range (1 , len (nums )):
11+ if nums [r ] != nums [r - 1 ] + 1 :
12+ res .append (
13+ f"{ nums [l ]} ->{ nums [r - 1 ]} " if l != r - 1 else f"{ nums [r - 1 ]} "
14+ )
15+ l = r
16+ res .append (f"{ nums [l ]} ->{ nums [- 1 ]} " if l != len (nums ) - 1 else f"{ nums [- 1 ]} " )
17+ return res
Original file line number Diff line number Diff line change 1+ class Solution :
2+ def calculate (self , s : str ) -> int :
3+ stack = []
4+ result = 0
5+ sign = 1
6+ num = 0
7+
8+ for ch in s :
9+ if ch .isdigit ():
10+ num = num * 10 + int (ch )
11+ elif ch in "+-" :
12+ result += sign * num
13+ num = 0
14+ sign = 1 if ch == "+" else - 1
15+ elif ch == "(" :
16+ stack .append (result )
17+ stack .append (sign )
18+ result = 0
19+ sign = 1
20+ elif ch == ")" :
21+ result += sign * num
22+ num = 0
23+ result *= stack .pop ()
24+ result += stack .pop ()
25+
26+ return result + sign * num
Original file line number Diff line number Diff line change 1+ from typing import List
2+
3+
4+ class Solution :
5+ def singleNumber (self , nums : List [int ]) -> List [int ]:
6+ res = 0
7+ for num in nums :
8+ res = res ^ num
9+
10+ diff_bit = 1
11+ while not (res & diff_bit ):
12+ diff_bit <<= 1
13+
14+ a , b = 0 , 0
15+ for n in nums :
16+ if diff_bit & n :
17+ a = a ^ n
18+ else :
19+ b = b ^ n
20+ return [a , b ]
Original file line number Diff line number Diff line change 1+ from typing import List
2+
3+
4+ class Solution :
5+ def findMinArrowShots (self , points : List [List [int ]]) -> int :
6+ if not points :
7+ return 0
8+
9+ # Sort balloons by their ending coordinate
10+ points .sort (key = lambda x : x [1 ])
11+ arrows = 1
12+ end = points [0 ][1 ]
13+
14+ for x_start , x_end in points [1 :]:
15+ if x_start > end :
16+ # Need a new arrow
17+ arrows += 1
18+ end = x_end # update arrow position
19+
20+ return arrows
Original file line number Diff line number Diff line change 1+ class Solution :
2+ def simplifyPath (self , path : str ) -> str :
3+ components = path .split ("/" )
4+ st = []
5+
6+ for comp in components :
7+ if comp == "" or comp == "." :
8+ continue
9+
10+ if comp == ".." :
11+ if st :
12+ st .pop ()
13+ else :
14+ st .append (comp )
15+
16+ return "/" + "/" .join (st )
Original file line number Diff line number Diff line change @@ -17,15 +17,15 @@ This repository contains my solutions to various LeetCode problems. Each solutio
1717
1818### Easy Problems
1919
20- - ** Total Solved:** [ 45 ]
20+ - ** Total Solved:** [ 46 ]
2121
2222### Medium Problems
2323
24- - ** Total Solved:** [ 116 ]
24+ - ** Total Solved:** [ 118 ]
2525
2626### Hard Problems
2727
28- - ** Total Solved:** [ 28 ]
28+ - ** Total Solved:** [ 29 ]
2929
3030## 🛠️ Languages Used
3131
You can’t perform that action at this time.
0 commit comments