自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 [leetcode] 258. Add Digits

题目: Given a non-negative integer num, repeatedly add all its digits until the result has only one digit. For example: Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2

2017-07-30 20:26:39 153

原创 [leetcode] 257. Binary Tree Paths

题目: Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree: 1 / \ 2 3 \ 5 All root-to-leaf paths are: ["1->2->5", "1->3"]

2017-07-30 20:15:56 125

原创 java中字符串相等问题

java中判断两个字符串是否相等的问题 我最近刚学java,今天编程的时候就遇到一个棘手的问题,就是关于判断两个字符串是否相等的问题。在编程中,通常比较两个字符串是否相同的表达式是“==”,但在java中不能这么写。在java中,用的是equals(); 例:A字符串和B和字符串比较: if(A.equals(B)){ } 返回true 或false. String 的equa

2017-07-30 19:22:22 200

原创 [leetcode] 234. Palindrome Linked List

题目: Given a singly linked list, determine if it is a palindrome. Follow up: Could you do it in O(n) time and O(1) space? 题解: 这道题让我们判断一个链表是否为回文链表,LeetCode中关于回文串的题共有六道,除了这道,其他的五道为Palindrome

2017-07-27 21:29:25 198

原创 [leetcode] 231. Power of Two

题目 Given an integer, write a function to determine if it is a power of two. 判断一个数是否是2的次方数 解法一:如果一个数是2的幂,则除以2肯定能整除,最后商为1 public boolean isPowerOfTwo(int n){ if(n<=0) return false; while

2017-07-27 19:55:03 174

原创 [leetcode] 205. Isomorphic Strings

题目 Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrences of a character must be replaced w

2017-07-26 20:25:28 179

原创 [leetcode] 204. Count Primes

题目: Count the number of prime numbers less than a non-negative number, n. 题解: 这道题给定一个非负数n,让我们求小于n的质数的个数,题目中给了充足的提示,解题方法就在第二个提示埃拉托斯特尼筛法Sieve of Eratosthenes中,这个算法的过程如下图所示,我们从2开始遍历到根号n,先找到第一个质数2,

2017-07-26 19:52:57 154

原创 [leetcode] 198. House Robber

题目 You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjace

2017-07-25 21:43:40 163

转载 [leetcode]175 Second Highest Salary

Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | Salary | +----+--------+ | 1 | 100 | | 2 | 200 | | 3 | 300 | +----+--------+ For examp

2017-07-24 14:53:25 228

原创 [leetcode] 172 Factorial Trailing Zeroes

题目: Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. 题解: 给定一个整数n,返回n!(n的阶乘)数字中的后缀0的个数。 注意:你的解法应该满足多项式时间复杂度

2017-07-24 14:41:33 144

原创 [leetcode] 167.Two Sum II - Input array is sorted

题目 Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number. The function twoSum should return indices of the tw

2017-07-21 15:31:02 157

原创 [leetcode] 141.Linked List Cycle

题目 Given a linked list, determine if it has a cycle in it. Follow up: Can you solve it without using extra space? 判断一个链表是否有环 这道题是快慢指针的经典应用。只需要设两个指针,一个每次走一步的慢指针和一个每次走两步的快指针,如果链表里有环的话,两个指针最

2017-07-20 15:58:21 150

原创 [leetcode] 136 single number

题目: Given an array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without us

2017-07-20 15:38:21 168

原创 图的深度优先搜索(DFS)和广度优先搜索(BFS)

1.遍历 图的遍历,所谓遍历,就是对结点的访问,一个图有那么多的结点,如何遍历这些结点,需要特定的策略,一般有两种访问策略: 深度优先搜索和广度优先搜索 2.深度优先搜索DFS 深度优先搜索,从图的任一顶点V1开始,输出顶点V1,将V1作为当前顶点,寻找当前顶点的邻接点V2,并进行如下判断:如果目前尚未输出顶点V2,则输出V2,V2成为新的当前顶点,继续这个过程;如果V2已经输

2017-07-11 16:56:37 1281

原创 基数排序

原理类似桶排序,这里总是需要10个桶,多次使用 首先以个位数的值进行装桶,即个位数为1则放入1号桶,为9则放入9号桶,暂时忽视十位数 例如 待排序数组[62,14,59,88,16]简单点五个数字 分配10个桶,桶编号为0-9,以个位数数字为桶编号依次入桶,变成下边这样 |  0  |  0  | 62 |  0  | 14 |  0  | 16 |  0  |  88 | 59 |

2017-07-10 17:07:49 125

原创 快速排序

假设我们现在对“6 1 2 7 9 3 4 5 10 8”这个10个数进行排序。首先在这个序列中随便找一个数作为基准数(不要被这个名词吓到了,就是一个用来参照的数,待会你就知道它用来做啥的了)。为了方便,就让第一个数6作为基准数吧。接下来,需要将这个序列中所有比基准数大的数放在6的右边,比基准数小的数放在6的左边,类似下面这种排列: 3 1 2 5 4 6 9 7 10 8

2017-07-09 16:51:54 179

原创 KMP 字符串模式匹配算法

1.一般字符串匹配过程传统匹配思想是,从目标串Target的第一个字符开始扫描,逐一与模式串的对应字符进行匹配,若该组字符匹配,则检测下一组字符,如遇失配,则退回到Target的第二个字符,重复上述步骤,直到整个Pattern在Target中找到匹配,或者已经扫描完整个目标串也没能够完成匹配为止。      这样的算法理解起来很简单,实现起来也容易,但是其中包含了过多不必要的操作,也就是在目

2017-07-08 15:02:25 1921

转载 B树插入删除操作

插入 想想2-3树的插入。2-3树结点的最大容量是2个元素,故当插入操作造成超出容量之后,就得分裂。同样m-阶B树规定的结点的最大容量是m-1个元素,故当插入操作造成超出容量之后也得分裂,其分裂成两个结点每个结点分m/2个元素。(副作用是在其父结点中要插入一个中间元素,用于分隔这两结点。和2-3树一样,再向父结点插入一个元素也可能会造成父结点的分裂,逐级向上操作,直到不再造成分裂

2017-07-07 11:02:58 2349 1

原创 对象序列化

对象序列化是指将那些实现了Serializable接口的对象转换成一个字节序列,使其以后能够将这个字节序列完成恢复为原来的对象。通过将一个序列化对象写入磁盘,然后在重新调用程序时恢复该对象,就能够实现持久性的效用。序列化的过程就是将对象写入字节流和从字节流中读取对象。将对象状态转换成字节流之后,可以用Java.io包中的各种字节流类将其保存到文件中,管道到另一线程中或通过网络连接将对象数据发送到另

2017-07-06 21:14:14 362

原创 java io 编程题

1.将a.txt文件中的单词与b.txt文件中的单词交替合并到c.txt文件中,a.txt文件中的单词用回车符分隔,b.txt文件中用回车或空格进行分隔 class FileManager{ String[] words=null; public FileManager(String filename,char[] seperator) throws IOException{

2017-07-06 20:57:31 854

原创 java io 字节流 字符流

1.流的概念 在程序中,所有的数据都是以流的形式进行传输和保存的,当程序需要数据的时候要使用输入流读取数据,而当程序需要保存数据时要使用输出流写数据 2.字节流和字符流 字节流:处理单元为1个字节,操作字节和字节数组,在字节流中输出数据用OutputStream,输入使用InputStream 字符流:处理单元为由2个字节组成的Unicode字符,操作字符、字符数组或字符串,在字符流中输出

2017-07-06 14:44:16 258

空空如也

空空如也

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

TA关注的人

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