LeetCode
文章平均质量分 72
Batman_
这个作者很懒,什么都没留下…
展开
-
LeetCode 2016 290,299,13
290 WordPatternclass Solution {public: bool wordPattern(string pattern, string str) { bool flag[30]={0}; vector word; word.clear(); word.resize(30); int原创 2016-02-18 13:36:01 · 287 阅读 · 0 评论 -
LeetCode 2016 423,412,409,89,29,166,91,79
423 Reconstruct Original Digits from Englishclass Solution{public: void makeSch(vector > &sch) { sch.push_back(make_pair('g'-'a',8)); sch.push_back(make_pair('u'-'a',4));原创 2016-12-15 22:37:57 · 329 阅读 · 0 评论 -
LeetCode 2016 424,187,200,376,390,354,15,18,419
424 Longest Repeating Character Replacementclass Solution {public: int characterReplacement(string s, int k) { int ans=0; int ls=s.size(); vector letters; in原创 2016-12-15 22:42:08 · 304 阅读 · 0 评论 -
LeetCode 2016 380,42,11,4,438,229,56,312
380 Insert Delete GetRandom O(1)class RandomizedSet {public: /** Initialize your data structure here. */ RandomizedSet() { s.clear(); } /** Inserts a value to the set.原创 2016-12-15 22:47:58 · 322 阅读 · 0 评论 -
LeetCode 2016 45,57,414,413,289,106,105
45 Jump Game IIclass Solution {public: int jump(vector& nums) { int len=nums.size(); if (len==1) return 0; int ans=0,maxPos=0,lastmax=0; for(int i=0;i<len-1;原创 2016-12-15 22:51:15 · 517 阅读 · 0 评论 -
LeetCode 2016 123,381,331,375,86,207,210
123 Best Time to Buy and Sell Stock IIIclass Solution {public: int maxProfit(vector& prices) { int len=prices.size(); if (len<2) return 0; int release2=0,hold2=INT_M原创 2016-12-15 22:56:02 · 374 阅读 · 0 评论 -
LeetCode 2016 310,304,145,98,301,388,99
310 Minimum Height Treesclass Solution{public: vector findMinHeightTrees(int n, vector >& edges) { vector > grid; int len=edges.size(); grid.clear(); grid.r原创 2016-12-15 22:59:42 · 498 阅读 · 0 评论 -
LeetCode 2016 332,127,25,23,143,114
332 Reconstruct Itineraryclass Solution {public: bool sign; vector ans; vector anstmp; int n; int ntickets; vector >used; vector > road; map relation; map itosre原创 2016-12-15 23:05:11 · 266 阅读 · 0 评论 -
LeetCode 2016 5,214,336,76,30,32,60
5 Longest Palindromic Substringclass Solution{public: string str; int len; string longestPalindrome(string s) { str = s; len = s.size()-1; return force();原创 2016-12-15 23:08:48 · 275 阅读 · 0 评论 -
LeetCode 2016 406,386,404,394,399
406 Queue Reconstruction by Heightclass Solution {public: vector > reconstructQueue(vector >& people) { int len=people.size(); vector > ans; ans.clear(); sor原创 2016-12-15 22:33:31 · 300 阅读 · 0 评论 -
LeetCode 2016 392,337,309,201,416
392 Is Subsequenceclass Solution {public: bool isSubsequence(string s, string t) { int ls = s.length(), lt= t.length(); if (ls==0) return true; int ps=0; boo原创 2016-12-15 22:27:16 · 325 阅读 · 0 评论 -
LeetCode 2016 8,357,367,69,378
8 String to Integer (atoi)class Solution {public: int myAtoi(string str) { int ans=0,len=str.length(),flag=1; if (len==0) return ans; int st=0; bool cntflag=原创 2016-12-15 22:23:31 · 290 阅读 · 0 评论 -
LeetCode 2016 282,241
282 Expression Add Operatorsclass Solution {public: vector ans; long long int strtoNum(string str) { long long int p=1; if (str[0]=='-') { p=-1;原创 2016-03-07 22:36:54 · 303 阅读 · 0 评论 -
LeetCode 2016 313,264,95,224,279,275,274
313 Super Ugly Numberclass Solution {public: int nthSuperUglyNumber(int n, vector& primes) { vector cnt(primes.size(),0); vector result(n,0); result[0]=1; fo原创 2016-03-08 15:26:51 · 533 阅读 · 0 评论 -
LeetCode 2016 345,342,38,257,303,278
345 Reverse Vowels of a Stringclass Solution {public: string reverseVowels(string s) { int len=s.length(); if (len==0) return ""; int flag[300]={0}; flag['原创 2016-05-13 09:13:20 · 447 阅读 · 0 评论 -
LeetCode 2016 338,347,343
338 Counting Bitsclass Solution {public: vector countBits(int num) { vector ans; ans.clear(); ans.resize(num+1); ans[0]=0; int p; if (num<=0)原创 2016-05-13 15:47:10 · 523 阅读 · 0 评论 -
LeetCode 2016 213,109
213 House Robber IIclass Solution {public: int rob(vector& nums) { int len=nums.size(); if (len==0) return 0; if (len==1) return nums[0]; vectorf; f.原创 2016-03-15 11:34:47 · 319 阅读 · 0 评论 -
LeetCode 2016 47,31
47 Permutations IIclass Solution {public: vector > permuteUnique(vector& nums) { sort(nums.begin(),nums.end()); vector > ans; ans.push_back(nums); while (nex原创 2016-03-18 11:30:54 · 302 阅读 · 0 评论 -
LeetCode 2016 167,382
167 Two Sum II - Input array is sortedclass Solution {public: vector twoSum(vector& numbers, int target) { vector ans; ans.clear(); int len=numbers.size(); i原创 2016-12-15 22:13:36 · 253 阅读 · 0 评论 -
LeetCode 2016 349, 383, 387, 384, 350, 374, 377
349 Intersection of Two Arraysclass Solution {public: vector intersection(vector& nums1, vector& nums2) { settmpans; vector ans; int ln1=nums1.size(),ln2=nums2.size(原创 2016-12-15 22:20:13 · 388 阅读 · 0 评论 -
LeetCode 2016 400,398,397,396,393,352,284
400 Nth Digitclass Solution {public: vector f; vector g; vector tens; int dUpper = 10; int th = 9; void countNumbers() { long long ten = 1; long long nin原创 2016-12-15 23:12:32 · 298 阅读 · 0 评论 -
LeetCode 2016 327,315,372,368,363,330,239
327 Count of Range Sum// See the discuss// See the analysis and using the code from:// http://www.cnblogs.com/jdneo/p/5388501.html// It is a solution combining the two pointers & merge sort// Th原创 2016-12-15 23:16:27 · 607 阅读 · 0 评论 -
LeetCode 2016 139,140,220
139 Word Break// Thought:// After several fails, I finally made it!// Core thought: convert the dic words according to the string s to vector of intervals// then, sort the intervals, and mark原创 2016-12-17 10:27:40 · 45621 阅读 · 0 评论 -
LeetCode Summary Dynamic Programming
============================ Dynamic Programming ===============================斐波那契f[i]:第i个的值70. Climbing Stairs(1或2步爬楼梯)f[i]=f[i-1]+f[i-2];91. Decode Ways(编码方式的个数)int tmp=((s[i-1]-'0原创 2017-02-10 17:05:32 · 373 阅读 · 0 评论 -
LeetCode Summary Graph
========================================== Graph =========================================------------------------------------ Topological Sort ------------------------------------207. Course原创 2017-02-10 17:06:05 · 396 阅读 · 0 评论 -
LeetCode Summary Hash Table
============================= Hash Table =============================36. Valid Sudoku(判断一个表格是不是数独)S1(Mine): 每行每列分别计数即可49. Group Anagrams(使用相同字母的单词分在同一组)S1(Mine): 每个单词排序,排好序后相同的字符串,用map记录在an原创 2017-02-10 17:06:51 · 346 阅读 · 0 评论 -
LeetCode Summary Linked List
============================== Linked List ============================复制138. Copy List with Random Pointer(复制一个乱七八糟的链表)S1(Mine): 用递归,指向什么,就新生成一个node,让这个node等于递归当前点指向的东西 用hash记录节点地原创 2017-02-10 17:07:29 · 323 阅读 · 0 评论 -
LeetCode Summary Math
============================ Math ====================================343. Integer Break(给定一个数n,拆成乘积最大的一堆数)要三不要二 要二不要一约数倍数365. Water and Jug Problem(容器量出指定水)Discuss: 转换成了GCD400.原创 2017-02-10 17:08:08 · 465 阅读 · 0 评论 -
LeetCode Summary Search
=========================== Search ===================================------------------------------ Backtracking ----------------------------------------找到所有子集39. Combination Sum 40. Combi原创 2017-02-10 17:08:55 · 390 阅读 · 0 评论 -
LeetCode Summary Sort
============================ Sort =================================------------------------- Merge Sort --------------------------88. Merge Sorted Array(合并2个有序数组):朴素315. Count of Smaller原创 2017-02-10 17:09:26 · 386 阅读 · 0 评论 -
LeetCode Summary STL Stack Queue
--------------------------------- map/set/vector -----------------------------------------380. Insert Delete GetRandom O(1)(设计一个数据结构,可以插入、删除、随机返回元素)381. Insert Delete GetRandom O(1) - Duplicates a原创 2017-02-10 17:09:59 · 437 阅读 · 0 评论 -
LeetCode Summary Array and Matrix
=========================================== Array ========================================中位数4. Median of Two Sorted Arrays(两有序数列,求他们的中位数,O(log (m+n)).)S1:最朴素,两个数列归并排序,选取中间位置。S2:two pointe原创 2017-02-10 17:03:57 · 460 阅读 · 0 评论 -
LeetCode 2016 132,68,71,97,10,44
132 Palindrome Partitioning II// ----------------Seeing Discuss-----------/* copying codes url https://discuss.leetcode.com/topic/2840/my-solution-does-not-need-a-table-for-palindrome-is-it-rig原创 2016-12-29 16:19:23 · 418 阅读 · 0 评论 -
LeetCode 2016 37,65,212,84,130,218
37 Sudoku Solver// ----------------Seeing Discuss-----------/* copying codes url https://discuss.leetcode.com/topic/5002/a-simple-dfs-solution Analysis: */class Solution {public: bool is原创 2016-12-29 16:16:21 · 139555 阅读 · 4 评论 -
LeetCode 2016 307
307 Range Sum Query - Mutable// Segment Tree with build, update, query// Pay attention to the size of segTree[], may cause REclass NumArray{public: NumArray(vector &nums) { num=n原创 2016-12-21 23:12:36 · 1456 阅读 · 0 评论 -
LeetCode 2016 134
134 Gas Station// ----------Seeing Discuss---------------// Here is the Analysis from the Discuss// """ 1. If car starts at A and can not reach B. Any station between A and B// can not reach B.原创 2016-12-21 23:13:41 · 23811 阅读 · 0 评论 -
LeetCode 2016 373,322,324,316
373 Find K Pairs with Smallest Sumsclass Solution {public: struct Node { int sum,i,j; Node(int s,int x,int y):sum(s),i(x),j(y){}; }; vector sums; static bool cmp原创 2016-12-21 23:16:53 · 543 阅读 · 0 评论 -
LeetCode 2016 391,297,87,93
391 Perfect Rectangle// -------------------Seeing Discuss & Searching the Solutions// Analysis:/* 任意一个矩形均有4个顶点,当出现Perfect Rectangle时,在最大覆盖矩形内部, 所有其它矩形的任意一个顶点均会出现偶数次(因为一个矩形旁边应当有一个或三个矩形 和它紧密相连,那么原创 2016-12-21 23:21:34 · 354 阅读 · 0 评论 -
LeetCode 2016 295,188,321,135,335
295 Find Median from Data Stream// I thought maybe can use two heaps, one is min heap, one is max heap. // keep the balance of the two heaps, the size equall, or min is 1 greater than max// min-he原创 2016-12-21 23:22:08 · 6170 阅读 · 0 评论 -
LeetCode 2016 385,365,211,115
385 Mini Parser// -------------------- Seeing Discuss -----------// I really have no idea about this kind of problem// I just retyped the codes from discuss// url:// https://discuss.leetcode.co原创 2016-12-27 17:09:53 · 395 阅读 · 0 评论