- 博客(21)
- 资源 (7)
- 收藏
- 关注
原创 LeetCode(26)Remove Duplicates From Sorted Array
题目如下Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place
2013-12-31 08:37:38 1512
原创 LeetCode(27)Remove Element
题目如下Given an array and a value, remove all instances of that value in place and return the new length.The order of elements can be changed. It doesn't matter what you leave beyond the new length.
2013-12-31 05:19:12 1157
原创 LeetCode(25)Reverse Nodes in K-Group
题目如下Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as i
2013-12-31 02:29:55 1206
原创 LeetCode(24)Swap Nodes in Pairs
题目如下:Given>/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public:
2013-12-26 04:10:42 1972
原创 LeetCode(72)Edit Distance
题目Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a wor
2013-12-23 13:27:56 5445 1
原创 LeetCode(23)Merge K Sorted Lists
题目如下:Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.分析:题目意思明确。可以仿照归并排序的思路来进行。需要考虑一些情况,比如lists[i]如果在作为函数的输入,可能会在一开始就是NULL。处理到中途,可能lists[i]对应
2013-12-21 16:27:23 4657
原创 LeetCode(22)GenerateParentheses
题目如下:Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())",
2013-12-19 14:32:10 2362
原创 LeetCode(20) Valid Parentheses
题目如下Given a string containing justthe characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all v
2013-12-19 06:04:40 3594
原创 LeetCode(19) Remove Nth Node From End of List
题目如下:Given a linked list, remove the Nth node from the end of list and return its head.For example,Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the
2013-12-18 14:30:51 2154 1
原创 LeetCode(17) Letter Combinations of a Phone Number
题目如下,输入一串数字,根据电话键盘布局输出此数字可能代表的字母组合。Given a digit string, return all possible letter combinations that the number could represent.Input:Digit string "23"Output: ["ad", "ae", "af", "bd", "be", "bf
2013-12-17 09:06:14 1165
原创 LeetCode(14) Longest Common Prefix
题目:Write a function to find the longest common prefix string amongst an array of strings.我的做法是,首先,先扫描一遍字符串数组,找到最短的字符串,时间复杂度为O(N)。然后把这个字符串的第1个字符作为标杆,在循环中依次检查数组中剩下的元素,看看是否第1个字符相等。如果循环完了数组的所有字符串,都发现它
2013-12-13 03:35:40 1060
原创 LeetCode(13) RomanToInteger
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.本题是把一个罗马数字转化为阿拉伯数字,和前道题目正好相反。我按照千位、百位、十位、个位的顺序依次处理罗马数字。在前一到题目的解答中,可以找到一个办法去简化代码,本题好像不怎么方
2013-12-11 10:42:45 3245
原创 LeetCode(12) IntegerToRoman
题目:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.比较基础的题目,没有用到什么数据结构和算法。使用了维基百科了解了罗马数字的书写规则。一开始按照个十百千的位数老老实实地写转换程序,写出来一看,啰嗦得囧。//啰嗦版
2013-12-10 08:36:43 2525
原创 LeetCode(11) ContainerWithMostWater
题目如下:Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fi
2013-12-09 08:23:48 4027 1
原创 SHELL小脚本_MAC下给照片重命名
如果去一个地方游玩拍照了,我一般都会整理照片,也会重命名照片,一般会命名为日期_地点_序号。如“2013-12-07在北京001”这样的。Windows下,total commander很好地帮我解决了重命名的任务。在Mac下,实验了mac自带的Automator,实验了几款重命名的小app,都不太理想。那还是写个shell 脚本吧。每次使用时,把PREFIX变量(照片文件名的统一的部
2013-12-07 16:25:49 2849
原创 LeetCode(10)RegularExpresssionMatching
这道题目我觉得挺难的,想了很久也没想清楚。If you are stuck, recursion is your friend.
2013-12-06 07:19:34 3665
原创 字符数组与整型数组的初始化和赋值对比
字符数组1 字符数组在定义的时候最好要初始化。 2 字符数组在初始化时,可以用2种形式第一种字符数组的初始化char a1[4]="abc";第二种字符数组的初始化 char a2[4]={'a','b','c','\0'}; 3 字符串和字符串数组之间存在着转化。上面的"abc"和{'a','b','c','\0'}可以经过相互转换后变得一样。在"abc"末尾,会
2013-12-06 03:03:39 18780 1
原创 LeetCode(9)PalindromeNumber
这道题,巨汗,提交了好几次才成功,我的基本思路就是不断地比较第i位和倒数第i位,知道遇到最中间的1个数字(输入为奇数个数字)或者遇到最中间的2个数字(输入为偶数个数字)。比较特殊的是,本题要求不能用额外的空间,所以无法借用之前的一道判断字符串是否为回文的题目的经验了。这几个case造成了前几次的失败: Input: 1001 Output: false
2013-12-05 03:26:54 3078
原创 LeetCode(8)StringToInteger
本题要求自己实现atoi函数,输入为一个string,输出为相应的int型integer.主要考察能否全面地考虑到输入的不同情况。比如输入"" 期待输出0输入" " 期待输出0输入" -a4" 期待输出0输入" -"
2013-12-04 08:18:30 3260
原创 LeetCode(7) Reverse Integer
本题比较简单,也比较坑爹,Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321题目明确提示了你要考虑反转后溢出的的问题。如果溢出了,返回什么都不合适,那就统一返回一个错误代码吧,return -1吧。这样写提交通过class Solution {p
2013-12-04 02:02:23 8283 5
原创 LeetCode(6)ZigZag Conversion
把一个字符串按照“之”字形复制在矩阵中,再把结果逐行逐列输出。原理和配图在这里。看上去题目很简单,实际上有些下标相关的东西我想了很久也debug了很久才弄清楚,更吐血的事情是,提交的时候说超时了。囧,说明办法太笨。之前采用的办法是new用一个二维数组作为中间变量,存入“之”字形字符串,再扫描一遍二维数组,把最终结果输出。这样老老实实地转换,时间当然消耗得久了。换了个办法,找到原字符串的下标和转换后
2013-12-01 03:27:40 3718
数据挖掘--概念.模型.方法和算法
2009-09-20
机器学习 Tom Mitchell 中文版
2009-09-20
机器学习英文版Machine Learning(Mitchell)(下)
2009-09-14
机器学习英文版Machine Learning(Mitchell)(中)
2009-09-14
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人