C++ basic
文章平均质量分 61
qq_34153219
这个作者很懒,什么都没留下…
展开
-
Reference:alias
Rule: 1.References must be initialized when defined. Initialization establishes a binding. eg: type& refname = name; //thus the value of refname is the same as name. 2.Bindings don’t cha原创 2017-02-06 08:29:59 · 232 阅读 · 0 评论 -
LintCode 407:Plus One
Note: The use of Vector: 1.initialize int x[10]={9,8,7,6,5,4,3,2,1,0}; vector test(x,x+10); 2.end();begin(); vector.begin() points to the first item,while vector.end() doesn't point to the原创 2017-02-06 08:39:29 · 340 阅读 · 0 评论 -
LintCode 156: Merge Intervals
Problem: Given a collection of intervals, merge all overlapping intervals. Solution:先按interval.start按升序进行冒泡排序,再逐一进行merge(如i1和i2比较,若可以merge再i1和后续比较,不可以merge则i2和i3等比较merge)。 Problem:冒泡排序耗时太长。 Mod原创 2017-02-08 11:09:11 · 269 阅读 · 0 评论 -
LintCode 480:Binary Tree Paths
Problem:Given a binary tree, return all root-to-leaf paths. Solution:每个结点记录从root至其的path,当结点无左右孩子时,将path传入进vector。 这里需要注意的是,recordPath函数中,path记录着root至结点的path,不可改变,不能加&(reference),而pathResul原创 2017-02-08 13:56:59 · 197 阅读 · 0 评论 -
LintCode 423:Valid Parentheses
Problem:Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. Solution:采用stack,当字符为上括号时push进stack,否之则从stack pop出字符看是否匹配。原创 2017-02-08 15:34:35 · 206 阅读 · 0 评论 -
LintCode 30:Insert Interval
跟merge intervals差不多的,没什么好说的。 class Solution { public: /** * Insert newInterval into intervals. * @param intervals: Sorted interval list. * @param newInterval: new interval.原创 2017-02-08 16:15:30 · 198 阅读 · 0 评论 -
LintCode 427:Generate Parentheses
Problem:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses. Solution:因为之前写过Valid Parentheses,所以一开始想的是把所有排列可能先找出来再验证。但是时间复杂度过于恐怖,达到了O(n!),枪毙此方法。原创 2017-02-10 10:57:16 · 216 阅读 · 0 评论 -
LintCode 442:Implement Trie
class TrieNode { public: // Initialize your data structure here. TrieNode* children[26]; bool flag;//check if it's the end of a word. TrieNode() :flag(0){ for(int i=0;i<26;i++)原创 2017-02-10 23:09:54 · 281 阅读 · 0 评论