
Algorithm
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 评论 -
1146. Topological Order (25) 拓扑排序
1146. Topological Order (25)时间限制200 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueThis is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topological order o...原创 2018-03-21 22:32:51 · 468 阅读 · 0 评论 -
1147. Heaps (30) 堆
1147. Heaps (30)时间限制200 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueIn computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node...原创 2018-03-21 21:59:09 · 522 阅读 · 0 评论 -
1144. The Missing Number (20)
1144. The Missing Number (20)时间限制150 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueGiven N integers, you are supposed to find the smallest positive integer that is NOT in the given list.Input Spec...原创 2018-03-21 21:02:26 · 1059 阅读 · 0 评论 -
1143. Lowest Common Ancestor (30) 最近公共祖先
1143. Lowest Common Ancestor (30)时间限制200 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueThe lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U and V as ...原创 2018-03-24 11:51:10 · 702 阅读 · 0 评论 -
1141. PAT Ranking of Institutions (25)
1141. PAT Ranking of Institutions (25)时间限制500 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueAfter each PAT, the PAT Center will announce the ranking of institutions based on their students' perfor...原创 2018-03-23 20:22:33 · 217 阅读 · 0 评论 -
1140. Look-and-say Sequence (20)
1140. Look-and-say Sequence (20)时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueLook-and-say sequence is a sequence of integers as the following:D, D1, D111, D113, D11231, D112213111, ...wh...原创 2018-03-23 20:16:46 · 233 阅读 · 0 评论 -
1142. Maximal Clique (25) 图
1142. Maximal Clique (25)时间限制400 ms内存限制65536 kB代码长度限制16000 B判题程序Standard作者CHEN, YueA clique is a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjac...原创 2018-03-23 12:57:00 · 223 阅读 · 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 评论 -
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 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 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 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 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 评论