Skip to content

Commit 7936563

Browse files
authored
Update First Bad Version - Leetcode 278.py
1 parent 6ce7911 commit 7936563

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

First Bad Version - Leetcode 278/First Bad Version - Leetcode 278.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
# Brute Force Solution
2+
class Solution:
3+
def firstBadVersion(self, n: int) -> int:
4+
for version in range(1, n+1):
5+
if isBadVersion(version):
6+
return version
7+
# Time: O(n)
8+
# Space: O(1)
9+
10+
# Optimal Solution
111
# The isBadVersion API is already defined for you.
212
# def isBadVersion(version: int) -> bool:
3-
413
class Solution:
514
def firstBadVersion(self, n: int) -> int:
615
L = 1
@@ -13,4 +22,6 @@ def firstBadVersion(self, n: int) -> int:
1322
else:
1423
L = M + 1
1524

16-
return L # Time: O(Log n), Space: O(1)
25+
return L
26+
# Time: O(Log n)
27+
# Space: O(1)

0 commit comments

Comments
 (0)