2235
class Solution:
def sum(self, num1: int, num2: int) -> int:
return num1 + num2
2469
class Solution:
def convertTemperature(self, celsius: float) -> List[float]:
return [celsius+273.15,celsius*1.80 + 32.00]
2413
class Solution:
def smallestEvenMultiple(self, n: int) -> int:
if n%2 == 0:
return n
else:
return 2*n
2236
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def checkTree(self, root: Optional[TreeNode]) -> bool:
left = root.left.val
right = root.right.val
if left + right == root.val:
return True
else:
return False
1486
class Solution:
def xorOperation(self, n: int, start: int) -> int:
res = start
for i in range(1,n):
res = res ^ (start + i*2)
return res
1512
class Solution:
def numIdenticalPairs(self, nums: List[int]) -> int:
res = 0
for i , x in enumerate(nums):
for j , y in enumerate(nums):
if i < j and x == y:
res += 1
return res
1534
class Solution:
def countGoodTriplets(self, arr: List[int], a: int, b: int, c: int) -> int:
n = len(arr)
res = 0
for i in range(n):
for j in range(n):
for k in range(n):
if not i < j < k:
continue
if abs(arr[i] - arr[j]) <= a and abs(arr[j] - arr[k]) <= b and abs(arr[i] - arr[k]) <= c:
res += 1
return res
584
# Write your MySQL query statement below
SELECT name FROM customer WHERE referee_id <> 2 OR referee_id IS NULL;
在MySQL中,需要对NULL进行特殊判断,上题中如果只判断是否等于2,会忽略掉id为NULL的行。(MySQL 使用三值逻辑 —— TRUE, FALSE 和 UNKNOWN)当我们拿一个非NULL值和一个NULL值,或者两个NULL值来比较时,会返回UNKNOWN。
1757
# Write your MySQL query statement below
Select product_id
from Products
where low_fats = 'Y' and recyclable = 'Y';
709
class Solution:
def toLowerCase(self, s: str) -> str:
return s.lower()
258
class Solution:
def addDigits(self, num: int) -> int:
if num == 0:
return num
return (num - 1)%9 + 1
1281
class Solution:
def subtractProductAndSum(self, n: int) -> int:
flag = 1
num = int(n)
s = 0
a = 1
while num > 0:
s += int(num%10)
a *= int(num%10)
if num%10 == 0:
flag = 0
num //= 10
return a - s
231
class Solution:
def isPowerOfTwo(self, n: int) -> bool:
if n == 1:
return True
if n%2 == 1 or n == 0:
return False
while math.fabs(n) > 0:
if n%2 == 1 and n != 1:
return False
n /= 2
return True
326
class Solution:
def isPowerOfThree(self, n: int) -> bool:
m = 1
while m < n:
m *= 3
if m == n:
return True
else:
return False
263
class Solution:
def isUgly(self, n: int) -> bool:
if n <= 0:
return False
while n > 1:
if n % 2 == 0:
n //= 2
elif n % 3 == 0:
n //= 3
elif n % 5 == 0:
n //= 5
else:
return False
return True
1470
class Solution:
def shuffle(self, nums: List[int], n: int) -> List[int]:
res = []
i = 0
j = n
while i < n and j < 2*n:
res.append(nums[i])
res.append(nums[j])
i += 1
j += 1
return res
867
class Solution:
def transpose(self, matrix: List[List[int]]) -> List[List[int]]:
res = [[0 for _ in range(len(matrix))] for _ in range(len(matrix[0]))]
for i in range(len(matrix)):
for j in range(len(matrix[0])):
res[j][i] = matrix[i][j]
return res
1422
class Solution:
def maxScore(self, s: str) -> int:
mid = 1
l = len(s)
res = 0
while mid < l:
ans = 0
for i in range(mid):
if s[i] == '0':
ans += 1
for j in range(mid,l):
if s[j] == '1':
ans += 1
mid += 1
res = max(res,ans)
return res
2586
class Solution:
def vowelStrings(self, words: List[str], left: int, right: int) -> int:
res = 0
for i in range(left,right + 1):
if words[i].startswith('a') or words[i].startswith('e') or words[i].startswith('i') or words[i].startswith('o') or words[i].startswith('u'):
if words[i].endswith('a') or words[i].endswith('e') or words[i].endswith('i') or words[i].endswith('o') or words[i].endswith('u'):
res += 1
return res
852
class Solution:
def peakIndexInMountainArray(self, arr: List[int]) -> int:
left = 0
right = len(arr) - 2
while left + 1 < right:
mid = (left + right) // 2
if arr[mid + 1] < arr[mid]:
right = mid
else:
left = mid
return right
892

被折叠的 条评论
为什么被折叠?



