
LintCode easy
文章平均质量分 67
qq_34153219
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
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 · 386 阅读 · 0 评论 -
LintCode 174:Remove Nth Node From End of List
Description: Given a linked list, remove the nth node from the end of list and return its head. Note: 需要注意的边界情况: 当需要删除的结点是head结点时,head会发生改变。 当n超过结点个数时,表明没有需要删除的结点。 Code: /** * Definiti原创 2017-08-26 21:49:08 · 253 阅读 · 0 评论 -
LintCode 372: Delete Node in the Middle of Singly Linked List
Description: Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node. Note: 1.拿到的是当前的结点,也就是说拿不到当前结点前一个结点,所以我把当前结点用下一个结点的值覆盖掉,再删掉下一个结点。原创 2017-08-26 21:46:21 · 237 阅读 · 0 评论 -
LintCode 245 : Subtree
Description: You have two every large binary trees: T1, with millions of nodes, and T2, with hundreds of nodes. Create an algorithm to decide if T2 is a subtree of T1. Notice: A tree T2 is a su原创 2017-08-26 20:30:32 · 304 阅读 · 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 · 247 阅读 · 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 · 237 阅读 · 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 · 254 阅读 · 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 · 330 阅读 · 0 评论 -
LintCode 433: Number of Islands
直接用了序贯算法写。然后发现!太麻烦了啊啊啊啊啊啊一道easy题写的心好累 (虽然时间复杂度挺好的。 class Solution { public: /** * @param grid a boolean 2D matrix * @return an integer */ int checkEqualList(vector >& equalL原创 2017-02-07 11:00:51 · 307 阅读 · 0 评论 -
LintCode 376: Binary Tree Path Sum
Description: Given a binary tree, find all paths that sum of the nodes in the path equals to a given number target. Note: 1.a valid path的定义是 from root node to any of the leaf nodes.所以当满足target条原创 2017-08-27 12:16:48 · 282 阅读 · 0 评论