1414 和为 K 的最少斐波那契数字数目
给你数字 k ,请你返回和为 k 的斐波那契数字的最少数目,其中,每个斐波那契数字都可以被使用多次。斐波那契数字定义为:
- F1 = 1
- F2 = 1
- Fn = Fn-1 + Fn-2 , 其中 n > 2 。 数据保证对于给定的 k ,一定能找到可行解。
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k
class Solution:
def findMinFibonacciNumbers(self, k: int) -> int:
f = [1, 1]
while f[-1] < k:
f.append(f[-1] + f[-2])
ans, i = 0, len(f) - 1
while k:
if k >= f[i]:
k -= f[i]
ans += 1
i -= 1
return ans
# 作者:LeetCode-Solution
# 链接:https://leetcode-cn.com/problems/find-the-minimum-number-of-fibonacci-numbers-whose-sum-is-k/solution/he-wei-k-de-zui-shao-fei-bo-na-qi-shu-zi-shu-mu-by/
1412 查找成绩处于中游的学生
select student_id,student_name from student where student_id not in
(
select student_id from(select student_id, rank() over(partition by exam_id order by score desc) as rk1 from exam ) a where rk1=1
union all
select student_id from(select student_id, rank() over(partition by exam_id order by score asc) as rk2 from exam ) b where rk2=1
union all
select student_id from student where student_id not in (select distinct student_id from exam)
)
order by student_id ;
# 作者:the-boondock-saints
# 链接:https://leetcode-cn.com/problems/find-the-quiet-students-in-all-exams/solution/wu-nao-fen-qing-kuang-tao-lun-you-dian-f-9d0w/