• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
yanqi
博客园 | 首页 | 新随笔 | 新文章 | 联系 | 订阅 订阅 | 管理

11 2015 档案

 
LeetCode() 数字1的个数
摘要:int ones = 0; for (long m = 1; m =2 三种情况: case 1: n=3141092, a= 31410, b=92. 计算百位上1的个数应该为 3141 *100 次. case 2: n=3141192, a= 31411, b=92. 计算百... 阅读全文
posted @ 2015-11-30 13:46 yanqi 阅读(245) 评论(0) 推荐(0)
LeetCode() Ugly Number II 背下来!
摘要:一个别人,非常牛逼的思路,膜拜了!orz!!!! vector results (1,1); int i = 0, j = 0, k = 0; while (results.size() < n) { results.push_bac... 阅读全文
posted @ 2015-11-29 21:26 yanqi 阅读(139) 评论(0) 推荐(0)
LeetCode() Partition List
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; *... 阅读全文
posted @ 2015-11-29 15:47 yanqi 阅读(157) 评论(0) 推荐(0)
LeetCode() Remove duplicates from sorted list II
摘要:ListNode* dummy = new ListNode(0); //必须要加上 new ListNode(0); 否则有错误。 dummy->next = head; head = dummy; while(head->next && head->next->next) { if(head->... 阅读全文
posted @ 2015-11-28 23:53 yanqi 阅读(119) 评论(0) 推荐(0)
LeetCode() Reorder List
摘要:超时,思路感觉很好,每次反转,/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(... 阅读全文
posted @ 2015-11-28 13:44 yanqi 阅读(125) 评论(0) 推荐(0)
LeetCode()Minimum Window Substring 超时,但觉得很清晰。
摘要:我的超时思路,感觉自己上了一个新的台阶,虽然超时了,但起码是给出了一个方法。遍历s 一遍即可,两个指针,当找到了一个合格的字串后,start 开始走,直到遇到s[start]在t中如果不符合,end++,直到遇到s[end]在t中。class Solution {public: st... 阅读全文
posted @ 2015-11-26 15:03 yanqi 阅读(151) 评论(0) 推荐(0)
LeetCode() Issomorphic Strings
摘要:bool isIsomorphic(string s, string t) { int size=s.size(); if (size==0) return true; char ch[128],ismap[128]; ... 阅读全文
posted @ 2015-11-25 23:50 yanqi 阅读(160) 评论(0) 推荐(0)
LeetCode() Repeated DNA Sequences 看的非常的过瘾!
摘要:All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to ... 阅读全文
posted @ 2015-11-25 21:29 yanqi 阅读(145) 评论(0) 推荐(0)
LeetCode()Substring with Concatenation of All Words 为什么我的超时呢?找不到原因了!!!
摘要:超时代码class Solution {public: vector findSubstring(string s, vector& words) { map coll; for(auto i:words) coll[i]++; ... 阅读全文
posted @ 2015-11-24 23:04 yanqi 阅读(156) 评论(0) 推荐(0)
LeetCode() Valid Anagram 有问题!!!
摘要:为什么第一个通过,第二个不行呢?class Solution {public: bool isAnagram(string s, string t) { if(s.size() != t.size()) return false; vector... 阅读全文
posted @ 2015-11-24 11:08 yanqi 阅读(106) 评论(0) 推荐(0)
LeetCode()Word Pattern
摘要:为什么我的算法不对呢,ab 可以检测,但超过两个不同的,就不对了先写在这里,哪天有思路了再看看// LeetCode.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include#include#include#include#includeusing name... 阅读全文
posted @ 2015-11-24 08:48 yanqi 阅读(155) 评论(0) 推荐(0)
LeetCode()Group Anagrams
摘要:改了又改,简化了又简化,还是超时。可见必须从数组本身来进行hash运算。class Solution {public: vector> groupAnagrams(vector& strs) { vector> res; int flag=0; for... 阅读全文
posted @ 2015-11-22 22:09 yanqi 阅读(134) 评论(0) 推荐(0)
LeetCode() Different Ways to Add Parentheses
摘要:分治的思想:1分2治3合并解这题最难的就是要想到 在运算符上分开。分治和递归是双胞胎啊!想不到啊想不到,不能再放纵自己了,眼睛干涩。vector diffWaysToCompute(string input) { vector result; for (int i = 0... 阅读全文
posted @ 2015-11-20 18:18 yanqi 阅读(133) 评论(0) 推荐(0)
LeetCode() Minimun Size Subarray Sum
摘要:别人的代码class Solution {public: int minSubArrayLen(int s, vector& nums) { int l, r, cum, res = nums.size()+1; l = r = cum = 0; while ((u... 阅读全文
posted @ 2015-11-19 22:43 yanqi 阅读(184) 评论(0) 推荐(0)
LeetCode() First Missing Positive
摘要:非常内疚,没想到这样的思路。思路:把数组上某一个位置的值放到正确的地方上去(nums[i-1] == i),nums[i] >0 && & A) { int i = 0; int n=A.size(); for (; i n || A[i] == A[A[i]... 阅读全文
posted @ 2015-11-19 19:27 yanqi 阅读(121) 评论(0) 推荐(0)
LeetCode() Find the Duplicate Number
摘要:Given an arraynumscontainingn+ 1 integers where each integer is between 1 andn(inclusive), prove that at least one duplicate number must exist. Assume... 阅读全文
posted @ 2015-11-19 13:43 yanqi 阅读(197) 评论(0) 推荐(0)
LeetCode() Search in Rotated Sorted Array
摘要:思路:先找到断点。估计还有更快的,不知道为什么,实在是不愿意去想这道题了class Solution {public: int search(vector& nums, int target) { int i,index=0; for(i=1;i=n... 阅读全文
posted @ 2015-11-18 14:54 yanqi 阅读(132) 评论(0) 推荐(0)
LeetCode() Search for a Range
摘要:class Solution {public: vector searchRange(vector& nums, int target) { vector res; vector xxx; xxx.push_back(-1); xxx.p... 阅读全文
posted @ 2015-11-18 13:46 yanqi 阅读(116) 评论(0) 推荐(0)
LeetCode() Search a 2D MatrixII
摘要:一开始的超时思路int row=a.size(),col=a[0].size(); for(int i=0;i target && a[i][0] target) low = mid-1; else ... 阅读全文
posted @ 2015-11-18 10:40 yanqi 阅读(109) 评论(0) 推荐(0)
LeetCode() Remove Duplicates from Sorted Array II
摘要:我的思路:先判断是不是有两个相等的,如果有,从2个之后查找还有几个相同的,start计数。class Solution {public: int removeDuplicates(vector& nums) { if(nums.size() == 0) re... 阅读全文
posted @ 2015-11-17 22:16 yanqi 阅读(156) 评论(0) 推荐(0)
LeetCode() Rotate Image
摘要:先改成对角线对换,然后再上下对换,如下所示1,2, 3, 45, 6, 7, 89, 10,11,1213,14,15,1616,12, 8, 415,11, 7, 314,10, 6, 213, 9, 5, 113, 9, 5, 114,10, 6, 215,11, 7, 316,12, 8, 4... 阅读全文
posted @ 2015-11-17 21:52 yanqi 阅读(112) 评论(0) 推荐(0)
LeetCode() Sort Colors
摘要:一个数组里有0,1,2三种数,排列非常牛逼的思路!!class Solution {public: void sortColors(vector& nums) { int i=-1,j=-1,k=-1; for(int p=0;p& nums) { ... 阅读全文
posted @ 2015-11-16 22:10 yanqi 阅读(130) 评论(0) 推荐(0)
LeetCode() Spiral Matrix
摘要:顺时针打印二维数组,以前在牛客网上做过,不过还是忘了 int n,m; vector > v; bool judge(int i,int j) { return i>=0 && i=0 && j printMatrix(vector > matrix) { ... 阅读全文
posted @ 2015-11-16 15:39 yanqi 阅读(174) 评论(0) 推荐(0)
LeetCode() Find Minimum in Rotated Sorted Array
摘要:不明白这个思路class Solution {public: int findMin(vector& num) { int size = num.size() - 1; int l = 0; int r = size; while(l n... 阅读全文
posted @ 2015-11-15 21:09 yanqi 阅读(110) 评论(0) 推荐(0)
LeetCode(169)Majority Element and Majority Element II
摘要:一个数组里有一个数重复了n/2多次,找到思路:既然这个数重复了一半以上的长度,那么排序后,必然占据了 a[n/2]这个位置。class Solution {public: int majorityElement(vector& nums) { sort(nums.begin(),... 阅读全文
posted @ 2015-11-15 14:31 yanqi 阅读(122) 评论(0) 推荐(0)
LeetCode(88) Merge Sorted Array
摘要:Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.非常好的思路:从两个数组的最后开始比较,直接放在了最后,因为已经知道了两个数组的长度,所以最后的坐标是 m+n-1 而每次比较后 ... 阅读全文
posted @ 2015-11-14 16:19 yanqi 阅读(95) 评论(0) 推荐(0)
LeetCode(283) Move Zeroes
摘要:class Solution {public: void moveZeroes(vector& nums) { int len=nums.size(); int start=0; for(int i=0;i<len;++i) { ... 阅读全文
posted @ 2015-11-14 16:11 yanqi 阅读(98) 评论(0) 推荐(0)
LeetCode(228) Summary Ranges
摘要:Given a sorted integer array without duplicates, return the summary of its ranges.For example, given[0,1,2,4,5,7], return["0->2","4->5","7"].class Sol... 阅读全文
posted @ 2015-11-13 15:55 yanqi 阅读(123) 评论(0) 推荐(0)
LeetCode(219) Contains Duplicate II
摘要:题意:Given an array of integers and an integerk, find out whether there are two distinct indicesiandjin the array such thatnums[i] = nums[j]and the diff... 阅读全文
posted @ 2015-11-13 10:29 yanqi 阅读(148) 评论(0) 推荐(0)
Subsets
摘要:我的思路:二进制位上有1则加class Solution {public: vector> subsets(vector& nums) { vector> res; sort(nums.begin(),nums.end()); for(int i=0;... 阅读全文
posted @ 2015-11-03 17:51 yanqi 阅读(267) 评论(0) 推荐(0)
Permutation Sequence
摘要:class Solution {public: int num=0; bool isgo=true;public: string getPermutation(int n, int k) { vector nums; for(int i=1;i> res; ... 阅读全文
posted @ 2015-11-03 14:11 yanqi 阅读(159) 评论(0) 推荐(0)
全排列 Permutations
摘要:class Solution {public: vector> permute(vector& nums) { sort(nums.begin(),nums.end()); vector> res; vector path; trackb... 阅读全文
posted @ 2015-11-03 12:04 yanqi 阅读(116) 评论(0) 推荐(0)
N皇后回溯解法 leetcode N-Queens
摘要:class Solution {public: vector > solveNQueens(int n) { vector> xxx; vector > res; vector com; int len=n; c3(res,com,n,len... 阅读全文
posted @ 2015-11-02 19:48 yanqi 阅读(231) 评论(0) 推荐(0)
 

公告


博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3