
leetcode
班黑炭
机器学习、数据挖掘
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
9. 回文数
判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。 示例 1: 输入: 121 输出: true 示例2: 输入: -121 输出: false 解释: 从左向右读, 为 -121 。 从右向左读, 为 121- 。因此它不是一个回文数。 示例 3: 输入: 10 输出: false 解释: 从右向左读, 为 01 。因此它不是一个回文数。 进阶: 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/pal.原创 2020-07-26 19:26:52 · 136 阅读 · 0 评论 -
11. 盛最多水的容器
给你 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点(i,ai) 。在坐标内画 n 条垂直线,垂直线 i的两个端点分别为(i,ai) 和 (i, 0)。找出其中的两条线,使得它们与x轴共同构成的容器可以容纳最多的水。 说明:你不能倾斜容器,且n的值至少为 2。 图中垂直线代表输入数组 [1,8,6,2,5,4,8,3,7]。在此情况下,容器能够容纳水(表示为蓝色部分)的最大值为49。 示例: 输入:[1,8,6,2,5,4,8,3,7] 输出:49...原创 2020-07-25 11:05:27 · 137 阅读 · 0 评论 -
6. Z 字形变换
将一个给定字符串根据给定的行数,以从上往下、从左到右进行Z 字形排列。 比如输入字符串为 "LEETCODEISHIRING"行数为 3 时,排列如下: L C I R E T O E S I I G E D H N 之后,你的输出需要从左往右逐行读取,产生出一个新的字符串,比如:"LCIRETOESIIGEDHN"。 请你实现这个将字符串进行指定行数变换的函数: string convert(string s, int numRows); 示例1: 输入: s = ...原创 2020-07-25 10:10:31 · 134 阅读 · 0 评论 -
3. 无重复字符的最长子串
给定一个字符串,请你找出其中不含有重复字符的最长子串的长度。 示例1: 输入: "abcabcbb" 输出: 3 解释: 因为无重复字符的最长子串是 "abc",所以其长度为 3。 示例 2: 输入: "bbbbb" 输出: 1 解释: 因为无重复字符的最长子串是 "b",所以其长度为 1。 示例 3: 输入: "pwwkew" 输出: 3 解释: 因为无重复字符的最长子串是"wke",所以其长度为 3。 请注意,你的答案必须是 子串 的长度,"pwke"是一个子序列,不是子串...原创 2020-07-21 23:41:52 · 147 阅读 · 0 评论 -
2. 两数相加
给出两个非空的链表用来表示两个非负的整数。其中,它们各自的位数是按照逆序的方式存储的,并且它们的每个节点只能存储一位数字。 如果,我们将这两个数相加起来,则会返回一个新的链表来表示它们的和。 您可以假设除了数字 0 之外,这两个数都不会以 0开头。 示例: 输入:(2 -> 4 -> 3) + (5 -> 6 -> 4) 输出:7 -> 0 -> 8 原因:342 + 465 = 807 class Solution(object):...原创 2020-07-21 22:30:39 · 106 阅读 · 0 评论 -
1. 两数之和
给定一个整数数组 nums和一个目标值 target,请你在该数组中找出和为目标值的那两个整数,并返回他们的数组下标。 你可以假设每种输入只会对应一个答案。但是,数组中同一个元素不能使用两遍。 示例: 给定 nums = [2, 7, 11, 15], target = 9 因为 nums[0] + nums[1] = 2 + 7 = 9 所以返回 [0, 1] 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/two-sum 著作...原创 2020-07-20 19:59:16 · 143 阅读 · 0 评论 -
169. 多数元素
给定一个大小为 n 的数组,找到其中的多数元素。多数元素是指在数组中出现次数大于⌊ n/2 ⌋的元素。 你可以假设数组是非空的,并且给定的数组总是存在多数元素。 示例1: 输入: [3,2,3] 输出: 3 示例2: 输入: [2,2,1,1,1,2,2] 输出: 2 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/majority-element 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 题解: ...原创 2020-07-20 19:36:00 · 112 阅读 · 0 评论 -
167. 两数之和 II - 输入有序数组
给定一个已按照升序排列的有序数组,找到两个数使得它们相加之和等于目标数。 函数应该返回这两个下标值 index1 和 index2,其中 index1必须小于index2。 说明: 返回的下标值(index1 和 index2)不是从零开始的。 你可以假设每个输入只对应唯一的答案,而且你不可以重复使用相同的元素。 示例: 输入: numbers = [2, 7, 11, 15], target = 9 输出: [1,2] 解释: 2 与 7 之和等于目标数 9 。因此 index1 = 1, ...原创 2020-07-20 19:22:08 · 117 阅读 · 0 评论 -
14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string"". Example 1: Input: ["flower","flow","flight"] Output:...原创 2019-08-14 12:58:41 · 153 阅读 · 0 评论 -
12. Integer to Roman
Roman numerals are represented by seven different symbols:I,V,X,L,C,DandM. Symbol Value I 1 V 5 X 10 L 50 C 100 D ...原创 2019-08-14 12:17:12 · 111 阅读 · 0 评论 -
[Leetcode]9. Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space.class Solution(object): def isPalindrome(self, x): """ :type x: int :rtype: bool """ ...原创 2018-04-09 11:45:19 · 199 阅读 · 0 评论 -
[Leetcode] 8. String to Integer (atoi)
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases....原创 2018-04-09 11:15:24 · 135 阅读 · 0 评论 -
[Leetcode] 7. Reverse Integer
Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123 Output: 321 Example 2:Input: -123 Output: -321 Example 3:Input: 120 Output: 21 Note:Assume we are dealing with an envi...原创 2018-03-05 20:57:09 · 177 阅读 · 0 评论