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. 计算百...
阅读全文
LeetCode() Ugly Number II 背下来!
摘要:一个别人,非常牛逼的思路,膜拜了!orz!!!! vector results (1,1); int i = 0, j = 0, k = 0; while (results.size() < n) { results.push_bac...
阅读全文
LeetCode() Partition List
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; *...
阅读全文
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->...
阅读全文
LeetCode() Reorder List
摘要:超时,思路感觉很好,每次反转,/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(...
阅读全文
LeetCode()Minimum Window Substring 超时,但觉得很清晰。
摘要:我的超时思路,感觉自己上了一个新的台阶,虽然超时了,但起码是给出了一个方法。遍历s 一遍即可,两个指针,当找到了一个合格的字串后,start 开始走,直到遇到s[start]在t中如果不符合,end++,直到遇到s[end]在t中。class Solution {public: st...
阅读全文
LeetCode() Issomorphic Strings
摘要:bool isIsomorphic(string s, string t) { int size=s.size(); if (size==0) return true; char ch[128],ismap[128]; ...
阅读全文
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 ...
阅读全文
LeetCode()Substring with Concatenation of All Words 为什么我的超时呢?找不到原因了!!!
摘要:超时代码class Solution {public: vector findSubstring(string s, vector& words) { map coll; for(auto i:words) coll[i]++; ...
阅读全文
LeetCode() Valid Anagram 有问题!!!
摘要:为什么第一个通过,第二个不行呢?class Solution {public: bool isAnagram(string s, string t) { if(s.size() != t.size()) return false; vector...
阅读全文
LeetCode()Word Pattern
摘要:为什么我的算法不对呢,ab 可以检测,但超过两个不同的,就不对了先写在这里,哪天有思路了再看看// LeetCode.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include#include#include#include#includeusing name...
阅读全文
LeetCode()Group Anagrams
摘要:改了又改,简化了又简化,还是超时。可见必须从数组本身来进行hash运算。class Solution {public: vector> groupAnagrams(vector& strs) { vector> res; int flag=0; for...
阅读全文
LeetCode() Different Ways to Add Parentheses
摘要:分治的思想:1分2治3合并解这题最难的就是要想到 在运算符上分开。分治和递归是双胞胎啊!想不到啊想不到,不能再放纵自己了,眼睛干涩。vector diffWaysToCompute(string input) { vector result; for (int i = 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...
阅读全文
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]...
阅读全文
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...
阅读全文
LeetCode() Search in Rotated Sorted Array
摘要:思路:先找到断点。估计还有更快的,不知道为什么,实在是不愿意去想这道题了class Solution {public: int search(vector& nums, int target) { int i,index=0; for(i=1;i=n...
阅读全文
LeetCode() Search for a Range
摘要:class Solution {public: vector searchRange(vector& nums, int target) { vector res; vector xxx; xxx.push_back(-1); xxx.p...
阅读全文
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 ...
阅读全文
LeetCode() Remove Duplicates from Sorted Array II
摘要:我的思路:先判断是不是有两个相等的,如果有,从2个之后查找还有几个相同的,start计数。class Solution {public: int removeDuplicates(vector& nums) { if(nums.size() == 0) re...
阅读全文
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...
阅读全文
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) { ...
阅读全文
LeetCode() Spiral Matrix
摘要:顺时针打印二维数组,以前在牛客网上做过,不过还是忘了 int n,m; vector > v; bool judge(int i,int j) { return i>=0 && i=0 && j printMatrix(vector > matrix) { ...
阅读全文
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...
阅读全文
LeetCode(169)Majority Element and Majority Element II
摘要:一个数组里有一个数重复了n/2多次,找到思路:既然这个数重复了一半以上的长度,那么排序后,必然占据了 a[n/2]这个位置。class Solution {public: int majorityElement(vector& nums) { sort(nums.begin(),...
阅读全文
LeetCode(88) Merge Sorted Array
摘要:Given two sorted integer arraysnums1andnums2, mergenums2intonums1as one sorted array.非常好的思路:从两个数组的最后开始比较,直接放在了最后,因为已经知道了两个数组的长度,所以最后的坐标是 m+n-1 而每次比较后 ...
阅读全文
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) { ...
阅读全文
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...
阅读全文
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...
阅读全文
Subsets
摘要:我的思路:二进制位上有1则加class Solution {public: vector> subsets(vector& nums) { vector> res; sort(nums.begin(),nums.end()); for(int i=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; ...
阅读全文
全排列 Permutations
摘要:class Solution {public: vector> permute(vector& nums) { sort(nums.begin(),nums.end()); vector> res; vector path; trackb...
阅读全文
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...
阅读全文
|
|
|