- 博客(480)
- 资源 (39)
- 收藏
- 关注
转载 leetcode(44) - Wildcard Matching
思路假设我们用两个指针分别指向s和p字符串中要匹配的位置,首先分析下通配符匹配过程中会有哪些情况是成功:s的字符和p的字符相等p中的字符是?,这时无论s的字符是什么都可以匹配一个p中遇到了一个*,这时无论s的字符是什么都没关系之前的都不符合,但是p在之前的位置有一个*,我们可以从上一个*后面开始匹配s已经匹配完,但是p后面还有很多连续的`*
2016-12-01 21:45:00
620
转载 leetcode(43) - Multiply Strings
思路 1 : 这道题属于数值操作的题目,其实更多地是考察乘法运算的本质。基本思路是和加法运算还是近似的,只是进位和结果长度复杂一些。我们仍然是从低位到高位对每一位进行计算,假设第一个数长度是n,第二个数长度是m,我们知道结果长度为m+n或者m+n-1(没有进位的情况)。对于某一位i,要计算这个位上的数字,我们需要对所有能组合出这一位结果的位进行乘法,即第1位和第i-1位,第2位和第i-2位,...
2016-11-30 23:04:31
600
原创 leetcode(42) - Trapping Rain Water
给定n个非负整数,代表一个柱状图,每一个柱子的宽度为1,计算下雨之后柱状图能装多少水?例如:[0,1,0,2,1,0,1,3,2,1,2,1] 返回 6 上述柱状图是由数组表示[0,1,0,2,1,0,1,3,2,1,2,1]。在这种情况下,6个单位的雨水(蓝色部分)被装。对于每个柱子,找到其左右两边最高的柱子,该柱子能容纳的面积就是
2016-11-29 15:28:25
642
转载 深度优先搜索(DFS)
1.前言深度优先搜索(缩写DFS)有点类似广度优先搜索,也是对一个连通图进行遍历的算法。它的思想是从一个顶点V0开始,沿着一条路一直走到底,如果发现不能到达目标解,那就返回到上一个节点,然后从另一条路开始走到底,这种尽量往深处走的概念即是深度优先的概念。你可以跳过第二节先看第三节,:)2.深度优先搜索VS广度优先搜索2.1演示深度优先搜索的过程还是引用上篇文
2016-11-27 23:19:41
603
转载 leetcode(39 40) - Combination Sum I/I I
深度优先搜索(DFS)是搜索算法的一种。最早接触DFS应该是在二叉树的遍历里面,二叉树的先序、中序和后序遍历实际上都属于深度优先遍历,实质就是深度优先搜索,后来在图的深度优先遍历中则看到了更纯正的深度优先搜索算法。 通常,我们将回溯法和DFS等同看待,可以用一个等式表示它们的关系:回溯法=DFS+剪枝。所以回溯法是DFS的延伸,其目的在于通过剪枝使得在深度优先搜索过程中如果满足
2016-11-27 23:01:05
384
转载 leetcode(38) - Count and Say
这是一道根据规则推导题目,要求给定序列数n,求出该序列对应的字符串。 char* countAndSay(int n) { if(n == 1) return "1"; char * cur = malloc(sizeof(char) * 2); char * temp; cur[0] = '1'; cur[1] = '\0';
2016-11-25 21:49:36
380
转载 leetcode(36) - Valid Sudoku 数独
Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character '.'.A partially fille
2016-11-23 20:03:36
449
原创 leetcode(35) - Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.
2016-11-22 21:47:13
362
原创 leetcode(34) - Search for a Range
Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If the target is not found in
2016-11-22 00:28:33
379
原创 leetcode(33) - Search in Rotated Sorted Array
int find(int* nums, int start, int end, int target) { if (start>end) return -1; int mid=0; while(start <= end){ mid=(start+end)/2; if (nums[mid] < target){
2016-11-21 23:59:38
316
转载 leetcode(32) - Longest Valid Parentheses 最长有效括号对
Given a string containing just the characters '(' and ')', find the length of the longest valid (well-formed) parentheses substring.For "(()", the longest valid parentheses substring is "()", which
2016-11-21 21:03:09
382
转载 leetcode(31) - Next Permutation
【题目】Implement 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
2016-11-18 21:24:56
397
转载 LeetCode(29) - Divide Two Integers
Problem:Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.Solution:不能乘除就加减就行了,但是一个问题是加减有可能速度太慢,因此需要转换,由于任何一个数都能表示成二进制,所以有d
2016-11-17 23:48:43
350
转载 leetCode(30) - Substring with Concatenation of All Words
Problem:You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in wordsexac
2016-11-17 23:46:40
299
原创 leetcode (28) - Implement strStr()
strstr(str1,str2) 函数用于判断字符串str2是否是str1的子串。如果是,则该函数返回str2在str1中首次出现的地址;否则,返回NULL。int strStr(char* haystack, char* needle) { int i = 0, j=0, index=0; int found=0, flag=0;
2016-11-15 16:23:39
431
原创 leetcode(27) - Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.
2016-11-14 17:16:27
425
原创 leetcode (26) - Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear onlyonce and return the new length.Do not allocate extra space for another array, you must do this in place with
2016-11-13 13:59:16
328
转载 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 it is.
2016-11-13 13:58:01
368
原创 leetcode(24) - Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y
2016-11-11 15:53:03
452
转载 leetcode (23) - Merge k Sorted Lists
算法1:最傻的做法就是先1、2合并,12结果和3合并,123结果和4合并,…,123..k-1结果和k合并,我们计算一下复杂度。1、2合并,遍历2n个节点12结果和3合并,遍历3n个节点123结果和4合并,遍历4n个节点…123..k-1结果和k合并,遍历kn个节点总共遍历的节点数目为n(2+3+…+k) = n*(k^2+k-2)/2, 因此时间复杂度是O(n*(k^
2016-11-10 22:07:28
366
原创 leetcode (23) - Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.借用了之前的两个已排序链表合并的代码,再依次遍历所有链表,进行两两合并,方法有点弱智,下篇转载一下别人的想法/** * Definition for singly-linke
2016-11-10 21:59:05
351
转载 leetcode (22) - Generate Parentheses
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:[ "((()))", "(()())", "(())()", "()(())",
2016-11-09 20:43:37
334
转载 linux中fork()函数详解
一、fork入门知识 一个进程,包括代码、数据和分配给进程的资源。fork()函数通过系统调用创建一个与原来进程几乎完全相同的进程,也就是两个进程可以做完全相同的事,但如果初始参数或者传入的变量不同,两个进程也可以做不同的事。 一个进程调用fork()函数后,系统先给新的进程分配资源,例如存储数据和代码的空间。然后把原来的进程的所有值都复制到新的新进程中,只有少数值与原来的进
2016-11-08 14:47:20
255
原创 leetcode (21) - Merge Two Sorted Lists
Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists./** * Definition for singly-linked list. * struct L
2016-11-08 09:02:06
254
原创 leetcode (20) - Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all va
2016-11-07 14:37:52
272
转载 leetcode (19) - Remove Nth Node From End of List
/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* removeNthFromEnd(struct ListNode* head, int n) { if(head
2016-11-06 11:38:09
219
原创 leetcode (18) - 4Sum
Given an array S of n integers, are there elements a,b, c, and d in S such that a + b +c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note: The solution s
2016-11-06 10:45:11
259
转载 leetcode (17) - Letter Combinations of a Phone Number
void getLetterCom(char** res,char* digits,char* tmp,int index,char map[10][5],int *top){ int i,digit=digits[index]-'0'; char* letters; if(digits[index]==0){ letters=(char*)malloc(si
2016-11-04 13:16:13
291
原创 leetcode (16) - 3Sum Closest
Given an array S of n integers, find three integers in S such that the sum is closest to a given number, target. Return the sum of the three integers. You may assume that each input would have exact
2016-11-03 13:15:15
218
转载 leetcode (15) - 3sum
void sort(int *a, int left, int right){ if(left >= right) { return ; } int i = left; int j = right; int key = a[left]; while(i < j) { while(i < j && key <=
2016-11-02 22:33:52
198
原创 leetcode (15) - 3sum
Given an array S of n integers, are there elements a,b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.Note: The solution set must not contain du
2016-11-02 22:31:32
345
原创 leetcode (14) - Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.char* longestCommonPrefix(char** strs, int strsSize) { int min_length = 0, min_index=0, i, j,tmp ;
2016-11-01 17:44:19
311
转载 leetcode (13) - ROMAN TO INT
class Solution {public: int romanToInt(string s) { int ret = toNumber(s[0]); for (int i = 1; i < s.length(); i++) { if (toNumber(s[i - 1]) < toNumber(s[i])) {
2016-11-01 16:13:34
264
转载 leetcode (12) - INT TO ROMAN
Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.思路首先,学习一下罗马数字,参考罗马数字罗马数字是最古老的数字表示方式,比阿拉伯数组早2000多年,起源于罗马罗马数字有如下符号:基本字
2016-11-01 13:56:41
188
转载 leetcode (11) - Container With Most Water
题意:在一个坐标系中,给出若干点,每个点做x轴的垂直线,然后求任何两条线形成的容器中能盛下最多水的情况分析:1.O(n^2)的算法,leetcode不给通过2. O(n)的算法,只能定性的分析,还不能形式化证明,这个必须得证明,否则不能保证正确性。定性说明:实际在二维坐标系中形成一个波动序列,从左开始与从右开始在分别到达极值之前,都有可能,之后的取值只有极值点才有可能出现变
2016-10-30 23:12:44
329
转载 leetcode(10) - Regular Expression Matching 正则表达式匹配
. 表示匹配任意字符* 表示匹配0个或多个字符bool isMatch(char* s, char* p) { if (*p == '\0') return *s == '\0'; // next char is not '*', then must match current character if (*(p + 1) != '*') {
2016-10-26 23:42:43
666
原创 leetcode (9) - Palindrome Number 整数回文
bool isPalindrome(int x) { bool is_flag=true; int reverse=0; int tmp=x; while(tmp) { if (reverse > (INT_MAX - tmp%10)/10 ) return false; reverse = revers
2016-10-25 20:06:08
223
原创 leetcode (8) - String to Integer
int myAtoi(char* str) { int length = strlen(str); int ret=0; int i=0; bool handle_flag=true; int plus_flag=0; int minus_flag=0; int ch=0; long ch_long=0;
2016-10-24 22:23:51
267
转载 leetcode (6) - ZigZag Conversion
The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)P A H NA P L S I I
2016-10-23 23:16:12
270
转载 leetcode (5) - Longest Palindromic Substring 最长回文子串
问题描述回文串是指这个字符串无论从左读还是从右读,所读的顺序是一样的;简而言之,回文串是左右对称的。现在,对于一个给定的母串abcdedcb可以找出子串a, ded, cdedc, bcdecdb等均是回文串;显然,bcdecdb是其中最长的那一个。但是该如何找出最长的回文子串呢?问题解法最容易想到的依然是穷举法,穷举所有子串,找出是回文串的子串,统计出最长的那一个。
2016-10-23 22:50:09
293
《Bootstrap实战》随书源码 (李松峰译,只有源码,不含PDF)
2017-01-16
北风网李炎恢jquery视频的讲义PDF+代码
2016-10-14
北风网李炎恢javascript视频的讲义PDF
2016-10-14
jdk1.6.0 _13.z01 (对应hadoop 0.20.0版本)
2014-04-15
轻量级Java_EE企业应用实战_(第三版).part5.rar
2014-01-08
轻量级Java_EE企业应用实战_(第三版).part4.rar
2014-01-08
轻量级Java_EE企业应用实战_(第三版).part3.rar
2014-01-08
轻量级Java_EE企业应用实战_(第三版).part2.rar
2014-01-08
轻量级Java_EE企业应用实战_(第三版).part1.rar
2014-01-08
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人