
LeetCode
zhangchaosd
一个人有梦想的时候,那天是他的生日。从梦想被放弃的那一刻开始,那个人就已经死了
展开
-
50. Pow(x, n) 面试题16. 数值的整数次方 快速解法
原题目链接 :https://leetcode-cn.com/problems/powx-n/思路:因为 n 是指数,所以可以把 n 分解为多个 2 的 j次方相加,于是就可以扫描 n 的二进制,每遇到一个 1,就通过迭代平方快速算出当前因子并乘到 ans 上n<0 时注意 n 为 INT_MIN 的情况class Solution {public: ...原创 2020-05-07 09:31:44 · 269 阅读 · 0 评论 -
1067. 范围内的数字计数 LeetCode C++
题目链接思路:用[1 - high] 的结果减去 [1 - low] 的结果;数位dp的方法,从最高位开始统计,注意处理 d 为 0 的情况。dp数组只是为了保存每次调用函数的结果,用来加快速度。时间复杂度和空间复杂度都是 O(n),n 为输入数字的位数class Solution { vector<int>s; int n; in...原创 2020-04-29 10:30:56 · 452 阅读 · 0 评论 -
LeetCode 5. Longest Palindromic Substring
Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example:Input: "babad"Output: "bab"Note: "aba" is also a valid answer. Example:I...原创 2018-03-15 15:48:44 · 115 阅读 · 0 评论 -
LeetCode 6. ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I I G...原创 2018-03-15 20:47:00 · 139 阅读 · 0 评论 -
LeetCode 7. Reverse Integer
Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21Note:Assume we are dealing with an envi...原创 2018-03-16 10:04:39 · 136 阅读 · 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-03-16 11:35:17 · 138 阅读 · 0 评论 -
LeetCode 3. 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 answer is "b", with the l...原创 2018-03-12 20:48:58 · 145 阅读 · 0 评论 -
LeetCode 4. Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).Example 1:nums1 = [1, 3]nums2...原创 2018-03-12 22:22:03 · 156 阅读 · 0 评论