![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
ToLiveXX
这个作者很懒,什么都没留下…
展开
-
LeetCode:01:Two Sum
题目描述: Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not us原创 2017-09-24 14:23:42 · 449 阅读 · 0 评论 -
LeekCode:03:Longest Substring Without Repeating Characters
问题描述: Given a string, find the length of the longest substring without repeating characters. Examples: Given “abcabcbb”, the answer is “abc”, which the length is 3. Given “bbbbb”, the原创 2017-09-24 16:37:35 · 187 阅读 · 0 评论 -
LeetCode:07: Reverse Integer
题目描述:(C++实现) Reverse digits of an integer. Example1: x = 123, return 321 Example2: x = -123, return -321 lick to show spoilers. Note: The input is assumed to be a 32-bit signed i原创 2017-09-24 21:02:21 · 174 阅读 · 0 评论 -
LeetCode 08:string to int(atoi)(C++实现)
原题描述: 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原创 2017-10-21 16:42:14 · 178 阅读 · 0 评论 -
LeetCode 633:平方数之和(C++实现)
题目:给定一个非负整数 c ,你要判断是否存在两个整数 a 和 b,使得 a2 + b2 = c。思路:使用双指针法,最小为0,最大为输入数的平方根,判断当前两个指针是否满足要求。示例1:输入: 5输出: True解释: 1 * 1 + 2 * 2 = 5示例2:输入: 3输出: FalseC++代码实现:class Solution {public: bool judgeSq...原创 2018-03-30 19:46:31 · 1904 阅读 · 0 评论 -
Leetcode 643:子数组最大平均数 (C++)
题目要求:给定 n 个整数,找出平均数最大且长度为 k 的子数组,并输出该最大平均数。例:输入: [1,12,-5,-6,50,3], k = 4输出: 12.75解释: 最大平均数 (12-5-6+50)/4 = 51/4 = 12.75思路:由于k值给定,因此只需要求出数组中连续k个和最大的数。 首先将前k个数的和保存到tmp中,res始终保存当前最大和。 ...原创 2018-03-30 20:47:48 · 990 阅读 · 0 评论 -
LeetCode 9:回文数
判断一个整数是否是回文数,不能使用辅助空间。说明:回文数是正着读反着读都一样的数字。思路1:分离出原数的每一位数字,保存在新的数组中,判断数组是否对称。But,不可行!原题目说明不能使用辅助空间,而且这种算法非常不高效。思路2:定义一个新的整数mul=0,做循环,每次都分离出原数的个位数,将分离出来的数重新组合成新数存在mul中,循环结束后,比较mul和原数是否相等。可行!class Soluti...原创 2018-03-29 17:08:55 · 210 阅读 · 1 评论