赵乐ACM

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

2013年8月11日

摘要: Implement wildcard pattern matching with support for'?'and'*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover the entire input string (not partial).The function prototype should be:bool i 阅读全文
posted @ 2013-08-11 09:05 赵乐ACM 阅读(350) 评论(0) 推荐(0) 编辑

2013年8月10日

摘要: Given two numbers represented as strings, return multiplication of the numbers as a string.Note: The numbers can be arbitrarily large and are non-negative.思路:大整数运算的思路,模拟乘法运算代码:class Solution {public: string multiply(string num1, string num2) { int len1 = num1.size(), len2 = num2.size(), le... 阅读全文
posted @ 2013-08-10 10:45 赵乐ACM 阅读(3042) 评论(1) 推荐(1) 编辑

2013年8月7日

摘要: Given an unsorted integer array, find the first missing positive integer.For example,Given[1,2,0]return3,and[3,4,-1,1]return2.Your algorithm should run inO(n) time and uses constant space.找到第一个没有出现的正整数思路:http://tech-wonderland.net/blog/leetcode-first-missing-positive.html就是把出现的正整数a都放在a-1的位置,然后从头开始历遍 阅读全文
posted @ 2013-08-07 16:59 赵乐ACM 阅读(1340) 评论(0) 推荐(0) 编辑

摘要: Given a collection of candidate numbers (C) and a target number (T), find all unique combinations inCwhere the candidate numbers sums toT.Each number inCmay only be usedoncein the combination.Note:All numbers (including target) will be positive integers.Elements in a combination (a1,a2, � ,ak) must 阅读全文
posted @ 2013-08-07 15:50 赵乐ACM 阅读(656) 评论(0) 推荐(0) 编辑

2013年7月22日

摘要: Reverse digits of an integer.Example1:x = 123, return 321Example2:x = -123, return -321比较简单,以下是步骤:1. 计算x的长度,就是有几位;2. 从低位开始,取余得到这一位的数字,然后乘以10^(len-i),再加到结果的数字上;上代码:class Solution {public: int reverse(int x) { // Start typing your C/C++ solution below // DO NOT write int main() functi... 阅读全文
posted @ 2013-07-22 23:23 赵乐ACM 阅读(546) 评论(0) 推荐(0) 编辑

摘要: nRows = 20 2 4 6 81 3 5 7 9nRows = 30 4 8 12 161 3 5 7 9 11 13 152 6 10 14nRows = 40 6 12 181 5 7 11 13 17 192 4 8 10 14 163 9 15可以发现规律1. 一块区域,即一个类似于“v”的形状为一个区域,区域的size是nRows*2-2;2. 在每一个区域中,只有第一行和最后一行有一个数,其余行每行包含两个数;3. 在除第一行和最后一行的其余行,第二个数和第一个... 阅读全文
posted @ 2013-07-22 22:22 赵乐ACM 阅读(312) 评论(0) 推荐(0) 编辑

摘要: 两种解法,动态规划和KMP变种动态规划,类似于lcs的解法,数组flag[i][j]记录s从i到j是不是回文首先初始化,i>=j时,flag[i][j]=true,这是因为s[i][i]是单字符的回文,当i>j时,为true,是因为有可能出现flag[2][1]这种情况,比如bcaa,当计算s从2到3的时候,s[2]==s[3],这时就要计算s[2+1] ?= s[3-1],总的来说,当i>j时置为true,就是为了考虑j=i+1这种情况。接着比较s[i] ?= s[j],如果成立,那么flag[i][j] = flag[i+1][j-1],否则直接flag[i][j]=fa 阅读全文
posted @ 2013-07-22 20:51 赵乐ACM 阅读(10004) 评论(2) 推荐(1) 编辑

2013年6月28日

摘要: mysqldb需要安装64位的(http://ishare.iask.sina.com.cn/f/21839771.html),否则出现import _mysql ImportError: DLL load failed: %1 不是有效的 Win32 应用程序ImportError: this is MySQLdb version (1, 2, 3, 'final', 0), but _mysql is version (1, 2, 2, 'final', 0) 阅读全文
posted @ 2013-06-28 13:12 赵乐ACM 阅读(887) 评论(0) 推荐(0) 编辑

2013年6月26日

摘要: 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 linked list.Input:(2 -> 4 -> 3) + (5 -> 6 -> 4)Output:7 -> 0 -> 8解题思路:很简单,主要考察链表的操作,对链 阅读全文
posted @ 2013-06-26 11:48 赵乐ACM 阅读(3036) 评论(1) 推荐(1) 编辑

2013年6月25日

摘要: Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.解 阅读全文
posted @ 2013-06-25 22:08 赵乐ACM 阅读(13316) 评论(3) 推荐(2) 编辑