数据结构与算法
doublechen_it
开朗 乐观 自信
展开
-
LeetCode 题目之4 Add Binary
题目:Given two binary strings, return their sum (also a binary string). For example,a = "11"b = "1"Return "100". 分析:本题不可利用二进制转换成整数的方法,因为不知道二进制的位数,有可能会导致溢出,因而无法转换。应该采取直接利用字符串进行转换,并考虑二进制的进位问题。原创 2012-08-08 15:10:25 · 1136 阅读 · 0 评论 -
LeetCode题目之5 Add Two Numbers
题目:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a原创 2012-08-08 15:06:19 · 1071 阅读 · 0 评论 -
LeetCode之7 Climbing Stairs
题目:You are climbing a stair case. It takes n steps 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? 解析:本题目主要考虑递归和DP两种思想;但是递归的时原创 2012-08-09 22:25:10 · 805 阅读 · 0 评论 -
LeetCode题目之8 Combination Sum II
题目:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations inC where the candidate numbers sums to T.Each number in C may only be used once in the com原创 2012-08-10 21:30:01 · 638 阅读 · 0 评论 -
LeetCode题目9 Count and Say
题目:The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ... 1 is read off as "one 1" or 11.11 is read off as "two 1s" or 21.21 is read off as原创 2012-08-11 15:36:22 · 1095 阅读 · 0 评论 -
精确算出n的阶乘
输入不超过1000的正整数n,输出n!=1*2*3.。。。n的精确结果。样例:30输出:265252859812191058636308480000000分析:由于直接算肯定会超出整数的表示范围,所以要利用其存储在字符串中,由于1000!=4*10的2567次方,需要大概最大3000个数组就可以保存。再将数组中的数转存到string中输出。代码:#include #include #inclu原创 2012-08-15 17:09:16 · 1431 阅读 · 0 评论 -
LeetCode题目 Insert Interval
题目:Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start ti原创 2012-08-17 15:45:53 · 1620 阅读 · 0 评论 -
LeetCode题目 Jump Game II
题目:Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your原创 2012-08-18 11:20:02 · 1453 阅读 · 0 评论 -
求一个字符串中连续出现次数最多的子串
题目: 求一个字符串中连续出现次数最多的子串,例如:abcbcd 最多的子串为bc#include #include using namespace std;char substr[255];void findmaxsubstr(char *str){ int len=strlen(str); int count=0; int maxcount=0; for原创 2012-08-29 12:01:17 · 1070 阅读 · 1 评论