- 博客(33)
- 资源 (39)
- 收藏
- 关注
转载 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 578
原创 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 613
转载 深度优先搜索(DFS)
1.前言深度优先搜索(缩写DFS)有点类似广度优先搜索,也是对一个连通图进行遍历的算法。它的思想是从一个顶点V0开始,沿着一条路一直走到底,如果发现不能到达目标解,那就返回到上一个节点,然后从另一条路开始走到底,这种尽量往深处走的概念即是深度优先的概念。你可以跳过第二节先看第三节,:)2.深度优先搜索VS广度优先搜索2.1演示深度优先搜索的过程还是引用上篇文
2016-11-27 23:19:41 573
转载 leetcode(39 40) - Combination Sum I/I I
深度优先搜索(DFS)是搜索算法的一种。最早接触DFS应该是在二叉树的遍历里面,二叉树的先序、中序和后序遍历实际上都属于深度优先遍历,实质就是深度优先搜索,后来在图的深度优先遍历中则看到了更纯正的深度优先搜索算法。 通常,我们将回溯法和DFS等同看待,可以用一个等式表示它们的关系:回溯法=DFS+剪枝。所以回溯法是DFS的延伸,其目的在于通过剪枝使得在深度优先搜索过程中如果满足
2016-11-27 23:01:05 366
转载 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 362
转载 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 427
原创 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 343
原创 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 365
原创 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 302
转载 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 360
转载 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 381
转载 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 336
转载 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 282
原创 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 411
原创 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 400
原创 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 312
转载 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 351
原创 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 438
转载 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 353
原创 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 340
转载 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 315
转载 linux中fork()函数详解
一、fork入门知识 一个进程,包括代码、数据和分配给进程的资源。fork()函数通过系统调用创建一个与原来进程几乎完全相同的进程,也就是两个进程可以做完全相同的事,但如果初始参数或者传入的变量不同,两个进程也可以做不同的事。 一个进程调用fork()函数后,系统先给新的进程分配资源,例如存储数据和代码的空间。然后把原来的进程的所有值都复制到新的新进程中,只有少数值与原来的进
2016-11-08 14:47:20 239
原创 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 235
原创 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 260
转载 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 197
原创 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 248
转载 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 273
原创 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 204
转载 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 188
原创 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 335
原创 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 299
转载 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 240
转载 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 180
《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关注的人