Python 刷Leetcode题库,顺带学英语单词(45)
Count Primes
Count the number of prime numbers less than a non-negative number, n. [#204]
Example:
Input: 10
Output: 4
Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.
Minimum Size Subarray Sum
Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn't one, return 0 instead. [#209]
Example:
Input: s = 7, nums = [2,3,1,2,4,3]
Output: 2
Explanation: the subarray [4,3] has the minimal length under the problem constraint.
Follow up:
If you have figured out the O(n) solution, try coding another solution of which the time complexity is O(n log n).
Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. [#215]
Examples:
Input: [3,2,1,5,6,4] and k = 2
Output: 5
Input: [3,2,3,1,2,4,5,5,6] and k = 4
Output: 4
Note:
You may assume k is always valid, 1 ≤ k ≤ array's length.
题意:在未排序的数组中找出第k大的数
>>> KthLargest = lambda lst,k:sorted(lst,reverse=True).index(k-1)
>>> nums = [3,2,1,5,6,4]; k = 2
>>> KthLargest(nums, k)
5
>>> nums = [3,2,3,1,2,4,5,5,6]; k = 4
>>> KthLargest(nums, k)
4
>>>
>>> # 或者:
>>> KthLargest = lambda lst,k:list(reversed(sorted(lst))).index(k-1)
>>> nums = [3,2,1,5,6,4]; k = 2
>>> KthLargest(nums, k)
5
>>> nums = [3,2,3,1,2,4,5,5,6]; k = 4
>>> KthLargest(nums, k)
4
>>>
相关文章
- python qt是什么_初识Python与Qt「建议收藏」
- python-回文字符串[通俗易懂]
- java与python-如何对比Python和Java,只需三分钟告诉你!
- python监控网页内容变化_使用Python监控文件内容变化代码实例
- 【说站】python中INF值的介绍
- 【说站】python PyQt向工具栏添加小部件
- [Python人工智能] 十九.Keras搭建循环神经网络分类案例及RNN原理详解
- Python实现自动回复_python 微信机器人
- python抛出异常和捕获异常_Python异常
- Python:利用python代码编程实现将视频的avi格式转换为MP4格式
- python lambda表达式举例_Python中lambda表达式[通俗易懂]
- python中copy.deepcopy_Python eval
- 罗马字符转整数(python)
- python deepcopy函数_Python deepcopy
- Python pytest测试框架详解
- 下列python语句的输出结果是print_下列 Python语句的输出结果是「建议收藏」
- 记录第一个Python练习的过程
- 【测试开发】python系列教程:Python数据类型转换
- Python MetaClass元类详解
- python 使用socket远程发送命令并获得执行结果详解编程语言
- Python 的可逆加密算法DES实现详解编程语言
- 小白的Python之路 day5 python模块详解及import本质编程语言
- 在Linux上搭建Python开发环境(linux搭建python环境)
- python之event【事件】详解编程语言
- Python简易操作MySQL数据库指南(python操作mysql数据库)
- 少有人知的 Python “重试机制”
- Python中还原JavaScript的escape函数编码后字符串的方法