09 2018 档案

摘要:题目 代码class Solution {public: string longestPalindrome(string s) { if(s.size()==1) return s; string max=s.substr(... 阅读全文
posted @ 2018-09-17 21:14 李正浩 阅读(75) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: int lengthOfLongestSubstring(string s) { //用dic存储每个字符最后一次出现的位置 vector dic(255,-1); in... 阅读全文
posted @ 2018-09-17 21:13 李正浩 阅读(69) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: vector> groupAnagrams(vector& strs) { vector> res; unordered_map> table; for(auto i:s... 阅读全文
posted @ 2018-09-17 21:11 李正浩 阅读(78) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: void setZeroes(vector>& matrix) { if(matrix.size()==0) return; int lastRow=-1,H=ma... 阅读全文
posted @ 2018-09-17 18:59 李正浩 阅读(127) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: vector> threeSum(vector& nums) { //先固定住第一个数字,然后后面两个数字为 i+1和 nums.size()-1开始往中间缩小,并且要考虑数字重复的问题,时间复杂度... 阅读全文
posted @ 2018-09-17 18:55 李正浩 阅读(93) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: int missingNumber(vector& nums) { int result = nums.size(); for(int i=0;i<nums.size... 阅读全文
posted @ 2018-09-17 18:51 李正浩 阅读(90) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: bool isValid(string s) { stack sta; for(auto i:s) { switch(i) { ... 阅读全文
posted @ 2018-09-17 18:47 李正浩 阅读(69) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: vector> generate(int numRows) { vector> res; if(numRows==0) return res; fo... 阅读全文
posted @ 2018-09-17 18:46 李正浩 阅读(97) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: uint32_t reverseBits(uint32_t n) { n=(n>>16)|(n>8)|((n&0x00ff00ff)>4)|((n&0x0f0f0f0f)>2)|((n&0x3333... 阅读全文
posted @ 2018-09-17 18:43 李正浩 阅读(103) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: int hammingDistance(int x, int y) { int res=x^y; int num=1; int result=0; whil... 阅读全文
posted @ 2018-09-17 18:40 李正浩 阅读(124) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: bool isPowerOfThree(int n) { //3的19次方是3的倍数的最大值 //用换底公式 return n > 0 && (log(INT_MAX)/... 阅读全文
posted @ 2018-09-16 08:22 李正浩 阅读(99) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: int countPrimes(int n) { if(n<=2) return 0; int res=1; bool *prime = new b... 阅读全文
posted @ 2018-09-16 08:21 李正浩 阅读(124) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: vector fizzBuzz(int n) { vector res; for(int i=1;i>str; res.push_back(str); ... 阅读全文
posted @ 2018-09-16 08:19 李正浩 阅读(74) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: int rob(vector& nums) { if(nums.size()==0) return 0; if(nums.size()==1) ... 阅读全文
posted @ 2018-09-16 08:18 李正浩 阅读(75) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: int maxSubArray(vector& nums) { vector max(nums.size(),0); if(nums.size()==0) ret... 阅读全文
posted @ 2018-09-16 08:18 李正浩 阅读(73) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: int maxProfit(vector& prices) { if(prices.size()==0) return 0; vector salarys(pri... 阅读全文
posted @ 2018-09-16 08:16 李正浩 阅读(72) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: int climbStairs(int n) { if(n==1) return 1; int step=0; int step1=... 阅读全文
posted @ 2018-09-16 08:16 李正浩 阅读(113) 评论(0) 推荐(0) 编辑
摘要:题目 代码// Forward declaration of isBadVersion API.bool isBadVersion(int version);class Solution {public: int firstBadVersion(int n) { ... 阅读全文
posted @ 2018-09-16 08:14 李正浩 阅读(178) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: void merge(vector& nums1, int m, vector& nums2, int n) { int i=0; while(i<n) { ... 阅读全文
posted @ 2018-09-16 08:13 李正浩 阅读(93) 评论(0) 推荐(0) 编辑
摘要:一、int转string#include #include int main() { double f = 23.43; double f2 = 1e-9; double f3 = 1e40; double f4 = 1e-40; double... 阅读全文
posted @ 2018-09-16 08:08 李正浩 阅读(854) 评论(0) 推荐(0) 编辑
摘要:题目 代码/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNo... 阅读全文
posted @ 2018-09-15 08:34 李正浩 阅读(105) 评论(0) 推荐(0) 编辑
摘要:题目 代码/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNo... 阅读全文
posted @ 2018-09-15 08:32 李正浩 阅读(87) 评论(0) 推荐(0) 编辑
摘要:题目 代码/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNo... 阅读全文
posted @ 2018-09-15 08:28 李正浩 阅读(84) 评论(0) 推荐(0) 编辑
摘要:题目 代码/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNo... 阅读全文
posted @ 2018-09-15 08:08 李正浩 阅读(56) 评论(0) 推荐(0) 编辑
摘要:题目 代码/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNo... 阅读全文
posted @ 2018-09-15 08:06 李正浩 阅读(76) 评论(0) 推荐(0) 编辑
摘要:题目 代码/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), nex... 阅读全文
posted @ 2018-09-15 08:05 李正浩 阅读(64) 评论(0) 推荐(0) 编辑
摘要:题目 代码/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), nex... 阅读全文
posted @ 2018-09-15 08:03 李正浩 阅读(85) 评论(0) 推荐(0) 编辑
摘要:题目 代码/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), nex... 阅读全文
posted @ 2018-09-15 08:01 李正浩 阅读(83) 评论(0) 推荐(0) 编辑
摘要:题目 代码/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), nex... 阅读全文
posted @ 2018-09-15 07:59 李正浩 阅读(63) 评论(0) 推荐(0) 编辑
摘要:题目 代码/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), nex... 阅读全文
posted @ 2018-09-15 07:57 李正浩 阅读(76) 评论(0) 推荐(0) 编辑
摘要:题目 代码/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), ne... 阅读全文
posted @ 2018-09-14 08:23 李正浩 阅读(68) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: string longestCommonPrefix(vector& strs) { //题目要求的是必须从每个字符串的0索引开始计算公共前缀 if(strs.size()==0) ... 阅读全文
posted @ 2018-09-14 08:21 李正浩 阅读(123) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: int strStr(string haystack, string needle) { if(haystack.size()==0&&needle.size()==0) re... 阅读全文
posted @ 2018-09-14 08:18 李正浩 阅读(102) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: int myAtoi(string str) { int res=0,sign=1; int i=str.find_first_not_of(' '); if(st... 阅读全文
posted @ 2018-09-14 08:16 李正浩 阅读(84) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: bool isPalindrome(string s) { string res; for(int i=0;i='a'&&s[i]='A'&&s[i]='0'&&s[i]<='9'))... 阅读全文
posted @ 2018-09-14 08:14 李正浩 阅读(71) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: bool isAnagram(string s, string t) { //字符交换了位置,但是每个字符的个数是一样的 map res1,res2; if(s.size... 阅读全文
posted @ 2018-09-14 08:13 李正浩 阅读(72) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: int firstUniqChar(string s) { std::map table; //先用map存储,value是出现的次数 for(int i=0;i<s.s... 阅读全文
posted @ 2018-09-14 08:11 李正浩 阅读(84) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: int reverse(int x) { int rev = 0; while (x != 0) { int pop = x % 10; x ... 阅读全文
posted @ 2018-09-14 08:09 李正浩 阅读(82) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: string reverseString(string s) { for (int i=0,j=s.size()-1; i<=j; i++, j--) { std::swap(s[i],s[j]); }... 阅读全文
posted @ 2018-09-14 08:06 李正浩 阅读(86) 评论(0) 推荐(0) 编辑
摘要:题目代码class Solution {public: void rotate(vector>& matrix) { int n=matrix.size(); for(int i=0;i (0,3)(0,1) -> (1,3)(0,2) ->... 阅读全文
posted @ 2018-09-14 08:03 李正浩 阅读(114) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: bool isValidSudoku(vector>& board) { //判断9宫格 for(int i=1;i table; table[ boar... 阅读全文
posted @ 2018-09-13 15:37 李正浩 阅读(131) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: vector twoSum(vector& nums, int target) { vector res; std::map table; for(int i=0;i插入... 阅读全文
posted @ 2018-09-13 15:35 李正浩 阅读(96) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: void moveZeroes(vector& nums) { int numOfZero=0; for(int i=0;i=0) nums[i-numOfZer... 阅读全文
posted @ 2018-09-13 15:32 李正浩 阅读(146) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: vector plusOne(vector& digits) { int plusFlag=0; int isEnd=1; for(auto i=digits.rbegi... 阅读全文
posted @ 2018-09-13 15:29 李正浩 阅读(103) 评论(0) 推荐(0) 编辑
摘要:题目代码class Solution {public: vector intersect(vector& nums1, vector& nums2) { std::map table1,table2; vector result; ... 阅读全文
posted @ 2018-09-13 15:26 李正浩 阅读(81) 评论(0) 推荐(0) 编辑
摘要:题目代码class Solution {public: int singleNumber(vector& nums) { int temp=0; for(auto i:nums) { temp^=i; ... 阅读全文
posted @ 2018-09-13 11:01 李正浩 阅读(113) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: bool containsDuplicate(vector& nums) { std::map dic; for(auto i:nums) { di... 阅读全文
posted @ 2018-09-13 10:57 李正浩 阅读(80) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: void rotate(vector& nums, int k) { if(nums.size()==0||nums.size()==1) return; if(... 阅读全文
posted @ 2018-09-13 10:55 李正浩 阅读(118) 评论(0) 推荐(0) 编辑
摘要:题目 代码class Solution {public: int maxProfit(vector& prices) { //总的利润 int maxSalary=0; if(prices.size()==0) ... 阅读全文
posted @ 2018-09-13 10:52 李正浩 阅读(81) 评论(0) 推荐(0) 编辑
摘要:题目代码class Solution {public: int removeDuplicates(vector& nums) { if(nums.size()<=1) return nums.size(); int re... 阅读全文
posted @ 2018-09-13 10:46 李正浩 阅读(82) 评论(0) 推荐(0) 编辑
摘要:题目输入一个整数,输出该数二进制表示中1的个数。其中负数用补码表示。思路1、算术移位与逻辑移位在计算机指令中,移位操作是一种基本操作,是一种直接对二进制数据的位运算操作。而移位运算又包含了逻辑移位(logical shift)和算术移位(arithmetic shift)两种... 阅读全文
posted @ 2018-09-02 19:47 李正浩 阅读(123) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示
more_horiz
keyboard_arrow_up light_mode palette
选择主题