自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(69)
  • 收藏
  • 关注

原创 [leetcode-42]Trapping Rain Water(java)

问题描述: Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,2,1,0,1,3,2,1,2,

2015-07-31 15:36:24 629

原创 Combination Sum II

问题描述: Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combina

2015-07-31 13:08:50 356

原创 [leetcode-39]Combination Sum(java)

问题描述: Given a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.The same repeated number may be chosen from C unlimited numb

2015-07-31 11:02:36 1811

原创 [leetcode-66]plus one(java)

问题描述: Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.分析:这道题的题意是说,有一个非负的数组代表

2015-07-30 22:48:47 1009

原创 [leetcode-58]Length of Last Word(c)

问题描述: Given a string s consists of upper/lower-case alphabets and empty space characters ’ ‘, return the length of last word in the string.If the last word does not exist, return 0.Note: A word is def

2015-07-30 21:50:07 440

原创 [leetcode-43]Multiply Strings(java)

问题描述: 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.分析:分别构造两个函数,一个是计算字符串与单个字符的乘积。一个是一个字符串与一

2015-07-30 21:37:51 1016

原创 网站跟踪(web tracking)的原理

网站跟踪并不是什么新的技术,而只是一种比较常见的应用,甚至都谈不上新。这里想跟大家分享一下,里面有我的一些想法和思考,如果有不准确的地方,还请不吝赐教。为什么要跟踪现在大家对隐私都比较敏感,而且对互联网流氓都比较警惕,所以一旦提到“跟踪”字眼就会觉得很不舒服。那我们先谈谈为什么会有网站跟踪。作为服务提供商,我们当然会希望知道用户对所提供服务的态度,这在任何行业都是明显的,对传统行业而言,销量就是最

2015-07-30 14:08:34 11964

原创 [leetcode-38]count and say(java)

问题描述: 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 “one

2015-07-30 09:44:05 1228

原创 [leetcode-34]Search Insert Position(c)

问题描述: 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 arra

2015-07-29 17:22:34 473

原创 [leetcode-34]Search for a Range(C)

问题描述: 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

2015-07-29 17:02:38 352

原创 [leetcode-33]Search in Rotated Sorted Array(C)

问题描述: Suppose a sorted array is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might become 4 5 6 7 0 1 2).You are given a target value to search. If found in the array return it

2015-07-29 16:44:39 376 1

原创 [leetcode-31]Next Permutation(C)

问题描述: 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 possib

2015-07-29 14:20:22 317

原创 [leetcode-30]Substring with Concatenation of All Words(java)

问题描述: 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 words exactly once

2015-07-29 13:15:43 418

原创 计算机计算乘除法的原理

前言虽然我们在编程语言中可以直接使用+-/,但是对某些要求不能用/的情况下,我们有必要了解一下计算机是怎样完成乘除法的。首先,我们要明确一下计算机所能完成的最基本操作是:+(-)和左移右移。虽然ISA中一般都有MUL类指令,但是这些经过译码之后最终的元操作还是加法和移位指令。乘法实现我们知道在计算机中只有0和1,于是,就有了二进制计数,比如5 = 101. 抽象的说,任何一个数均可以表示为如

2015-07-28 17:24:22 52888 8

原创 【leetcode-29】Divide Two Integers(C)

问题描述: Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.分析:这道题不允许用*/和%运算,因此只能模拟计算机对乘除法的做法来进行。请参考另外一篇博客:这里写链接内容另外,这道题最恶心的是一些边界值。如被除数为-2147483

2015-07-28 16:20:53 2821

原创 [leetcode-26]Remove Duplicates from Sorted Array(C)

问题描述: 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 wi

2015-07-28 12:36:07 725

原创 [leetcode-25]Reverse Nodes in k-Group(C)

问题描述: 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

2015-07-28 11:29:58 329

原创 [leetcode-18]4Sum(java)

问题描述: 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: Elements in

2015-07-28 10:31:51 539

原创 [leetcode-17]Letter Combinations of a Phone Number(java)

问题描述: Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below. Input:Digit stri

2015-07-27 14:29:15 993

原创 【leetcode-16】3Sum Closest(java)

问题描述: 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 e

2015-07-27 13:31:47 722

原创 [leetcode-15]3Sum(java)

问题描述: 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: Elements in a triplet (a,b,c) mu

2015-07-27 12:50:51 596

原创 [leetcode-13]Roman to Integer(C)

问题描述: Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.代码分析:罗马数字转换成整数的规则如下:如果前一个数的值小于后一个数的值,那么这个数为后者减去前者。如果前者大于后者,那么就是简单地相加即可。代码如下:28msint getV

2015-07-27 09:13:48 572

原创 [leetcode-11]container with most water(C)

问题描述: 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). Find

2015-07-26 23:05:27 294

原创 Swap Nodes in Pairs(C语言)

问题描述: 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. You

2015-07-24 15:01:40 534

原创 [leetcode-20]Valid Parentheses(java)

问题描述: 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 vali

2015-07-24 14:54:18 299

原创 [leetcode-]Remove Nth Node From End of List(C)

问题描述: 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 linked

2015-07-24 14:39:49 366

原创 【leetcode-14】Longest Common Prefix(java)

问题描述: Write a function to find the longest common prefix string amongst an array of strings.代码如下:328ms public String longestCommonPrefix(String[] strs) { int row = strs.length; i

2015-07-24 14:04:49 591

原创 [leetcode-10]Regular Expression Matching(C)

问题描述: Implement regular expression matching with support for ‘.’ and ‘*’.‘.’ Matches any single character. ‘*’ Matches zero or more of the preceding element.The matching should cover the entire input

2015-07-24 11:24:26 625

原创 [leetcode-8]String to Integer (atoi)(java)

问题描述: Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input

2015-07-23 20:40:00 717 1

原创 【leetcode-36】valid sudoku(java)

问题描述: 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 ‘.’.分析:维护一个hash表,先按行查找,再按列查找,

2015-07-23 19:57:54 635

原创 ZigZag Conversion(java)

问题描述: 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 N A P L S

2015-07-23 17:02:57 419

原创 [leetcode 239]Sliding Window Maximum(c)

问题描述: Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding wi

2015-07-23 11:18:07 423

原创 [leetcode-240]Search a 2D Matrix II(C语言)

问题描述: Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right. Integers in

2015-07-23 10:04:15 475

原创 [leetcode-3]Longest Substring Without Repeating Characters(java)

问题描述: 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

2015-07-23 09:32:25 353

原创 数据结构与算法分析(C)1.4

问题描述:编写一个程序,使它读入被include语句修饰的一个文件并且输出这个文件。分析:这道题的思路很简单,首先,读入源文件,然后在源文件中查找#include,然后获取包含的文件名,然后fread到内存中,如此继续下去。 有个问题纠结了很久:当在查找过程中发现strcpy(include,”#include”);时也会出现”#include”字符,应该对它进行过滤。//include zuho

2015-07-22 22:15:32 1261

原创 数据结构与算法分析1.8

问题描述:2^100(mod 5)是多少?代码如下://1.8 2^100 (mod 5)#include <iostream>using namespace std;int pow(int m,int n,int d)//m^n mod d{ int index = 1; int base = m%d;//when index = 1 while(index*2<=n

2015-07-22 19:38:13 990

原创 只使用处理IO的printDigit函数,编写一个过程以输出任意实数

//只使用处理IO的printDigit函数,编写一个过程以输出任意实数(可以为负)#include <iostream>using namespace std;void printDigit(int num){ printf("%d",num);}void printOut(int num){ if(num>10) printOut(num/10);

2015-07-22 16:35:39 4498

原创 【数据结构与算法分析1.2】编写一个程序求解字谜游戏问题

问题描述:输入是由一些字母和单词构成的二维数组,目标是找出字谜中的单词,这些单词可以是水平、垂直或沿对角线以任何方向放置。找出二维数组中所有的单词写完这个程序,手都要断掉了,太TM麻烦了,而且效率很低,到底有多少个for循环,自己都数不清。//1.2编写一个程序求解字谜游戏问题#include <iostream>using namespace std;/** directions:

2015-07-22 15:15:12 6683

原创 数据结构与算法分析(C语言描述)L1.1

1.1编写一个程序解决选择问题,令k = N/2.画出表格显示你的程序对于N为不同值的运行时间。代码如下:#include #include using namespace std;int select(int A[],int k,int n){ int *minHeap = (int *)malloc(sizeof(int)*k); int heapSize = 0; in

2015-07-22 12:17:41 1719

原创 数据结构与算法分析第二章读书笔记

这本书第二章引发了一个问题,求最大子序列和,并给出了四种解题算法进行对比。问题描述:给定一个数组,求出该数组的最大子序列。算法1暴力搜索:即找出所有的子序列,并对其求和来与最大值比较。时间复杂度为O(n3);int maxSum1(int sum[],int start,int end){ int i,j,k; int maxSum = 0; int tmpSum;

2015-07-22 10:39:00 1351

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除