2014年4月7日

【LeetCode练习题】Reverse Linked List II

摘要: Reverse Linked List IIReverse a linked list from positionmton. Do it in-place and in one-pass.For example:Given1->2->3->4->5->NULL,m= 2 andn= 4,return1->4->3->2->5->NULL.Note:Givenm,nsatisfy the following condition:1 ≤m≤n≤ length of list.题目意思:翻转给定区间[m,n]的链表。第一个节点m=1。 1n 阅读全文

posted @ 2014-04-07 22:51 Allen Blue 阅读(2334) 评论(0) 推荐(0) 编辑

【C++】大数的+-*/四则运算

摘要: 所谓大数,则指数值特别大的数,可能会有99位,100位,远远超过了long long表示的范围。这样的数作四则运算,需要用到字符串。用字符串通过每一位的字符的四则运算来模拟。废话少说,上代码: 1 #include 2 #include 3 using namespace std; 4 5 class BigNum{ 6 vector m_vec; 7 //构造函数,析构函数,size()函数,友元重载>>,>(istream &is,BigNum &data); 23 24 public: 25 char operator[](int nInde... 阅读全文

posted @ 2014-04-07 16:50 Allen Blue 阅读(682) 评论(0) 推荐(0) 编辑

【LeetCode练习题】Multiply Strings

摘要: Multiply StringsGiven two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.题目意思:给两个string,计算string的乘积。string中的数可以非常大并且是非负数。(就是大数的乘法运算嘛。。。)解题思路:由于之前已经练习过了大数的加减乘除四则运算了,所以这道题跟那个是一样的原理。要想实现乘法,首先得实现大数的加法,因为按照小 阅读全文

posted @ 2014-04-07 16:46 Allen Blue 阅读(199) 评论(0) 推荐(0) 编辑

2014年4月5日

【LeetCode练习题】Evaluate Reverse Polish Notation

摘要: Evaluate Reverse Polish NotationEvaluate the value of an arithmetic expression inReverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another expression.Some examples: ["2", "1", "+", "3", "*"] -> ((2 + 1) * 3) -&g 阅读全文

posted @ 2014-04-05 17:47 Allen Blue 阅读(177) 评论(0) 推荐(0) 编辑

【LeetCode练习题】Merge k Sorted Lists

摘要: Merge k Sorted ListsMergeksorted linked lists and return it as one sorted list. Analyze and describe its complexity.题目意思:合并K条已经排序的链表。分析时间复杂度。解题思路:很容易就想起之前学的合并两条链表的算法,这一题其实就是那个题目的扩展,变成合并K条了。我采用的方法就是迭代法。如果只有一条,直接返回。如果只有两条,就只需要调用mergeTwo一下。如果超过两条链表的话,先将前两个链表调用mergeTwo,然后用新的链表和第三个链表调用mergeTwo,再用结果和第四个链表 阅读全文

posted @ 2014-04-05 16:50 Allen Blue 阅读(142) 评论(0) 推荐(0) 编辑

【LeetCode练习题】Next Permutation

摘要: Next PermutationImplement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible order (ie, sorted in ascending order).The replacement must be in-place, do not allocate 阅读全文

posted @ 2014-04-05 15:52 Allen Blue 阅读(550) 评论(0) 推荐(0) 编辑

《将夜》你究竟喜欢的是读书这件事情,还是读完所有书这件事情呢?

摘要: 生活中值得去读的好书实在太多了,我读不完怎么办?值得去看的好电影实在太多了,我看不完怎么办?值得去尝试的有意思的领域实在太多了,时间不够怎么办?如果你也常常会有这样的焦虑,这篇文章可能会帮到你。整整一面崖壁的书籍,漫山遍野看上去无穷无尽的书籍,对于一个爱读书甚至把读书视做生命里唯一要务的人来说,毫无疑问是莫大的宝藏,但同时也是莫大的悲哀,因为以有涯之生阅无尽之书,终究是不可能完成的任务。走出崖洞,再看着书桌后那位捧着书卷,不时抄录不时吟哦不时悲愤不时喜悦的老书生,宁缺发现自己有些明白他为什么会表现的如此极端,显得如此着急。走到书桌旁,宁缺对着苍老的读书人深深一礼,诚恳请教道:“这位师叔,如果书 阅读全文

posted @ 2014-04-05 14:20 Allen Blue 阅读(541) 评论(0) 推荐(0) 编辑

2014年4月4日

【LeetCode练习题】Climbing Stairs

摘要: Climbing StairsYou are climbing a stair case. It takesnsteps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?题目意思:上楼梯。假设要n步到达楼梯的顶部。每一次你只能上一个或两级台阶,问要到达顶部一共有多少种方法?解题思路:真是太巧了!!我今天刚刚在《剑指offer》里读到了一模一样的原题,在该书的75页。简单介绍一下吧:如果只有一级台阶,那显然只有一种 阅读全文

posted @ 2014-04-04 17:46 Allen Blue 阅读(182) 评论(0) 推荐(0) 编辑

【LeetCode练习题】Validate Binary Search Tree

摘要: Validate Binary Search TreeGiven a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keysless thanthe node's key.The right subtree of a node contains only nodes with keysgreater thanthe node' 阅读全文

posted @ 2014-04-04 17:26 Allen Blue 阅读(137) 评论(0) 推荐(0) 编辑

2014年4月2日

【LeetCode练习题】Remove Duplicates from Sorted List II

摘要: Remove Duplicates from Sorted List IIGiven a sorted linked list, delete all nodes that have duplicate numbers, leaving onlydistinctnumbers from the original list.For example,Given1->2->3->3->4->4->5, return1->2->5.Given1->1->1->2->3, return2->3.题目意思:凡是给定链表里出现的重 阅读全文

posted @ 2014-04-02 21:45 Allen Blue 阅读(102) 评论(0) 推荐(0) 编辑

导航