- 博客(40)
- 资源 (3)
- 收藏
- 关注
原创 LeetCode Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".题意:二进制的加法。思路:跟大数加法差不多。class Solution {public: string addBinary(string a,
2015-03-31 20:19:01 544
原创 LeetCode Plus One
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.题意:大数加法。class Soluti
2015-03-30 14:58:25 590
原创 N的阶乘中末尾有几个0
面试题目: 给定一个数n,求1*2*3*...*n 结果中末尾0的个数。思路:首先思考一个问题,一个数末尾有几个0的是不是可以等价于一个数能整除几次10呢,因为10是有2×5组成的,那么我们也就可以理解为这个数有几对2和5的组合的话,那么他就能等价于有几个0。举个例子:比如50=2×5×5,那么他有一对(2,5),所以它有1个0那么现在又有一个问题是:我们如何得到1×2×....×n之
2015-03-30 10:37:51 1052
原创 字符串全排序,非重复的全排序
题目:求一个字符串的全排列。思路:我们可以生成一个解答树:拿字符串“bca”来说,此时如果我们处理到第cur个位置,那么我们可以和从当前这个位置开始依次和之后的位置互换字符,这样就能确保二叉树每一层(当前位置)的结果都能出现过了,然后接着递归下去。package org;import java.util.Arrays;public class SortMethod { pu
2015-03-28 23:37:44 911
原创 LeetCdoe Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at
2015-03-28 09:25:38 577
原创 LeetCode Unique Paths II
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the
2015-03-28 00:07:09 701
原创 LeetCode Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the
2015-03-26 09:58:00 531
转载 Java的内存回收机制
在Java中,它的内存管理包括两方面:内存分配(创建Java对象的时候)和内存回收,这两方面工作都是由JVM自动完成的,降低了Java程序员的学习难度,避免了像C/C++直接操作内存的危险。但是,也正因为内存管理完全由JVM负责,所以也使Java很多程序员不再关心内存分配,导致很多程序低效,耗内存。因此就有了Java程序员到最后应该去了解JVM,才能写出更高效,充分利用有限的内存的程序。1
2015-03-25 22:42:09 442
原创 LeetCode Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL.题意:翻转链表。思路:注意这里的k可能是大于n的,所以要先
2015-03-25 13:23:33 532
原创 [百度]数组A中任意两个相邻元素大小相差1,在其中查找某个数。
题目数组A中任意两个相邻元素大小相差1,现给定这样的数组A和目标整数t,找出t在数组A中的位置。如数组:[1,2,3,4,3,4,5,6,5],找到4在数组中的位置。思路:对于目标target来说,当前数如果是和它相等的话,那么最起码需要跳abs(target-A[i]),因为如果不是递增或者递减的话,而是波动的话,那么它最起码要在abs(target-A[i])。impo
2015-03-24 23:01:09 809
原创 LeetCode Permutation Sequence
The set [1,2,3,…,n] contains a total of n! unique permutations.By listing and labeling all of the permutations in order,We get the following sequence (ie, for n = 3):"123""132""213""231""3
2015-03-23 13:42:39 602
原创 LeetCode Spiral Matrix II
Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order.For example,Given n = 3,You should return the following matrix:[ [ 1, 2, 3 ], [ 8, 9, 4 ], [
2015-03-21 12:32:44 616
原创 LeetCode Length of Last Word
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
2015-03-19 18:37:05 724
原创 一个简单的java聊天室
利用java Socket编写的群聊室,可以自己拷过去试试Server端:package net3;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import java.io.PrintWriter;import java.net.Ser
2015-03-19 11:20:17 24649 1
原创 LeetCode Insert Interval
Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start times.E
2015-03-18 19:57:37 707
原创 LeetCode Merge Intervals
Given a collection of intervals, merge all overlapping intervals.For example,Given [1,3],[2,6],[8,10],[15,18],return [1,6],[8,10],[15,18].题意:去掉重复的区间。思路:排序后,再比较end的情况。/** * Definition fo
2015-03-14 23:20:50 672
原创 LeetCode Jump Game
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Determine i
2015-03-13 20:28:47 534
原创 LeetCode Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]
2015-03-13 11:31:49 612
原创 LeetCode Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1] ha
2015-03-12 23:09:26 576
原创 LeetCode N-Queens II
Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.题意:还是n皇后问题。思路:时间复杂度要求高了,还是每行每行的放,再开一个三维的标记数组,y-x代表了主对角线,y+x代表了负对角
2015-03-11 12:28:28 631
转载 互联网协议入门(二)
上一篇文章分析了互联网的总体构思,从下至上,每一层协议的设计思想。这是从设计者的角度看问题,今天我想切换到用户的角度,看看用户是如何从上至下,与这些协议互动的。==============================================================互联网协议入门(二)作者:阮一峰(接上文)七、一个小结
2015-03-10 20:53:54 579
转载 互联网协议入门(一)
我们每天使用互联网,你是否想过,它是如何实现的?全世界几十亿台电脑,连接在一起,两两通信。上海的某一块网卡送出信号,洛杉矶的另一块网卡居然就收到了,两者实际上根本不知道对方的物理位置,你不觉得这是很神奇的事情吗?互联网的核心是一系列协议,总称为”互联网协议”(Internet Protocol Suite)。它们对电脑如何连接和组网,做出了详尽的规定。理解了这些协议,就理解了互联网
2015-03-10 20:53:24 544 1
原创 LeetCode N-Queens
The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each otherGiven an integer n, return all distinct solutions to the n-queens puzzle.Ea
2015-03-10 16:49:39 610
转载 Git详解之一:Git 分支
原文:《Pro Git》几乎每一种版本控制系统都以某种形式支持分支。使用分支意味着你可以从开发主线上分离开来,然后在不影响主线的同时继续工作。在很多版本控制系统中,这是个昂贵的过程,常常需要创建一个源代码目录的完整副本,对大型项目来说会花费很长时间。有人把 Git 的分支模型称为“必杀技特性”,而正是因为它,将 Git 从版本控制系统家族里区分出来。Git 有何特别
2015-03-09 22:35:51 5748 1
原创 LeetCode Pow(x, n)
Implement pow(x, n).思路:二分求,注意正负号就是了。class Solution {public: double cal(double x, int n) { if (n == 0) return 1.0; double tmp = pow(x, n>>1); if (n & 1
2015-03-09 16:05:56 585
原创 LeetCode Anagrams
Given an array of strings, return all groups of strings that are anagrams.Note: All inputs will be in lower-case.题意:给你string的数组,让你求出字符和个数都相同的字符串。思路:对于每个字符串都排序后,用map标记是否已经加入到答案中。class Solutio
2015-03-08 17:45:08 652
原创 LeetCode Rotate Image
You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?题意:矩阵旋转。思路:每次旋转的时候都一次性旋转4个数。class Solution {publ
2015-03-08 15:37:03 640
原创 LeetCode Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1].
2015-03-07 17:55:42 650
原创 LeetCode Permutations
Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].题意:生成所有的序列。思路
2015-03-07 14:08:42 702
原创 LeetCode Jump Game II
Given an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Your goal i
2015-03-07 00:18:15 730
转载 数据库事务隔离级别
事务隔离(isolation)定义了数据库系统中一个操作产生的影响什么时候以哪种方式可以对其他并发操作可见。隔离是事务ACID (原子性、一致性性、隔离性、持久性)四大属性中的一个重要属性。目录 [隐藏] 1 并发控制(Concurrency control)2 隔离级别(Isolation levels)2.1 可序列化(Serializab
2015-03-06 12:35:21 1212
原创 LeetCode Wildcard Matching
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 t
2015-03-06 10:41:47 608
原创 LeetCode Multiply Strings
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-03-06 00:15:58 649
原创 LeetCode Trapping Rain Water
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,1]
2015-03-05 12:49:48 551
原创 LeetCode First Missing Positive
Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant
2015-03-04 19:50:01 595
原创 LeetCode 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-03-04 10:58:09 567
原创 LeetCode Combination Sum
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-03-03 21:04:27 626
原创 LeetCode Count and Say
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
2015-03-03 13:37:03 656
原创 LeetCode Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells.Empty cells are indicated by the character '.'.You may assume that there will be only one unique solution.A sudoku
2015-03-02 13:58:05 843
原创 LeetCode 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
2015-03-01 15:13:10 670
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人