自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 String相关题目(左移字符串、翻转单词序列)

左移字符串 汇编语言中有一种移位指令叫做循环左移(ROL),现在有个简单的任务,就是用字符串模拟这个指令的运算结果。对于一个给定的字符序列S,请你把其循环左移K位后的序列输出。例如,字符序列S=”abcXYZdef”,要求输出循环左移3位后的结果,即“XYZdefabc”。是不是很简单?OK,搞定它!public class Solution { //调用三遍reverse方法,借助翻转单

2017-03-08 20:19:08 322 1

转载 数组排序(冒泡、选择、插入、快排、希尔、桶排序、堆排序)

1、冒泡排序 它是一种较简单的排序算法。它会遍历若干次要排序的数列,每次遍历时,它都会从前往后依次的比较相邻两个数的大小;如果前者比后者大,则交换它们的位置。这样,一次遍历之后,最大的元素就在数列的末尾! 采用相同的方法再次遍历时,第二大的元素就被排列在最大元素之前。重复此操作,直到整个数列都有序为止. 冒泡排序的时间复杂度是O(N2),是算法稳定的。 算法稳定性 – 假设在数列中存在a[i]

2017-02-28 10:34:56 532

原创 java中String、StringBuffer、StringBuilder的区别

现在来看三者的相同和不同之处 一、可变和不可以变 String类中使用字符数组保存字符串,如下就是,因为有“final”修饰符,所以可以知道string对象是不可变的。 private final char value[]; StringBuilder与StringBuffer都继承自AbstractStringBuilder类,在AbstractStringBuilder中也是使用字符数组

2017-02-28 09:14:43 237

转载 java中String、StringBuffer、StringBuilder的区别

java中String、StringBuffer、StringBuilder是编程中经常使用的字符串类,他们之间的区别也是经常在面试中会问到的问题。现在总结一下,看看他们的不同与相同。1.可变与不可变  String类中使用字符数组保存字符串,如下就是,因为有“final”修饰符,所以可以知道string对象是不可变的。    private final char valu

2017-01-05 17:08:36 198

转载 java中“==”和equal区别

“==”是用来比较两个String对象在内存中的存放地址是否相同的。String test1 = "test";String test2 = "test";String test3 = new String(test2);String test4 =new String(test2);blooean result1 = (test1==test2);blooean result2 = (t

2017-01-05 16:55:35 250

原创 Leetcode 184. Department Highest Salary

利用SQL语句找出每一个部门中工资最高的人的信息 原题 The Employee table holds all employees. Every employee has an Id, a salary, and there is also a column for the department Id.+----+-------+--------+--------------+| Id |

2017-01-04 21:14:42 655

原创 Leetcode177. Nth Highest Salary(SQL语句中使用函数)

原题 Write a SQL query to get the nth highest salary from the Employee table.+----+--------+| Id | Salary |+----+--------+| 1 | 100 || 2 | 200 || 3 | 300 |+----+--------+For example, g

2017-01-04 20:38:28 359

原创 Leetcode176. Second Highest Salary(MYSQL limit,offset 区别)

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

2017-01-04 17:08:31 325

原创 Leetcode338. Counting Bits

原题Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.Example:For num = 5 you s

2017-01-03 14:39:30 216

原创 Leetcode94. Binary Tree Inorder Traversal

原题Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree [1,null,2,3], 1 \ 2 / 3return [1,3,2]题意 中序遍历,将结果返回到list集合中 思路 采用栈的方式,遍历到的节

2017-01-03 14:04:46 183

转载 String,StringBuffer与StringBuilder的区别??

String 字符串常量 StringBuffer 字符串变量(线程安全) StringBuilder 字符串变量(非线程安全) 简要的说, String 类型和 StringBuffer 类型的主要性能区别其实在于 String 是不可变的对象, 因此在每次对 String 类型进行改变的时候其实都等同于生成了一个新的 String 对象,然后将指针指向新的 String 对象,所以经常改

2017-01-02 16:01:17 228

原创 Leetcode415. Add Strings

原题Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2.Note:The length of both num1 and num2 is < 5100.Both num1 and num2 contains only digits 0-9.Both

2017-01-02 15:50:52 183

原创 Leetcode290. Word Pattern

原题Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.Examples:

2016-12-31 21:56:06 195

原创 Leetcode205. 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 with another cha

2016-12-31 21:24:22 164

原创 Leetcode203. Remove Linked List Elements

原题Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5题意 给出一个链表和一个目标值,删除链表中与目标值相同的元素,然

2016-12-31 15:34:38 169

原创 Leetcode35. 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.Her

2016-12-28 17:30:23 181

原创 leetcode69. Sqrt(x)

原题 Implement int sqrt(int x). Compute and return the square root of x. 计算出x的开方的数组 思路 利用二分查找法,如果mid的乘方大于x,但是mid+1的乘方小于x就说明mid是x的开方的整数值。 但是在写的过程中,如果x的数值较大,mid的数值较大,可能会造成mid的平方过大做成数值溢出,所以可以换个角度来比较,乘

2016-12-28 17:25:30 284

原创 linux中修改删除挂载硬盘等常用命令

1、查看命令 查看文件夹中的内容 ls ll 2、查看文件夹中的文件个数 ls | wc -w是查看有多少个文件及文件夹 ls | wc -c这个查看目录下多少个文件.3、从root用户切换到其他用户 su4、更改文件夹的所属用户 使用chown命令可以修改文件或目录所属的用户:命令:chown 用户 目录或文件名例如:chown qq /home/qq

2016-12-28 14:04:18 1462

原创 Leetcode151. Reverse Words in a String

原题 Given an input string, reverse the string word by word.For example, Given s = “the sky is blue”, return “blue is sky the”.Update (2015-02-12): For C programmers: Try to solve it in-place in O(1)

2016-12-27 17:19:35 238

原创 Leetcode16. 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 exac

2016-12-25 17:14:59 167

原创 Leetcode345. Reverse Vowels of a String

原题 Write a function that takes a string as input and reverse only the vowels of a string.Example 1: Given s = “hello”, return “holle”.Example 2: Given s = “leetcode”, return “leotcede”.Note: The vo

2016-12-25 17:01:40 225

原创 Leetcode15. 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.For example, given array S = [-1, 0, 1, 2,

2016-12-25 12:05:47 185

原创 Leetcode118. Pascal's Triangle (杨辉三角)

原题 Given numRows, generate the first numRows of Pascal’s triangle. For example, given numRows = 5, Return[ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1]]思路 给出你行数,给出杨辉三角;杨辉三角如上图所示;可以吧杨

2016-12-22 21:57:25 202

原创 Spring

一、概念 - 它是为了解决企业应用开发的复杂性而创建的。框架的主要优势之一就是其分层架构,分层架构允许使用者选择使用哪一个组件,同时为 J2EE 应用程序开发提供集成的框架。Spring使用基本的JavaBean来完成以前只可能由EJB完成的事情。然而,Spring的用途不仅限于服务器端的开发。从简单性、可测试性和松耦合的角度而言,任何Java应用都可以从Spring中受益。Spring的核心是

2016-12-19 20:23:39 398

原创 数据库中的索引

数据库索引的类型哈希索引:基于哈希表实现,只有精确匹配索引所有列的查询才有效B-Tree索引:适用于全值索引、健值索引或者是键前缀索引 索引的优点索引大大减少服务器扫描的数据量所以可以帮助服务器避免排序和临时表索引可以将随机的I/O变成顺序的I/O 高性能的索引策略独立的列:将索引列单独放在比较符号的一侧。前缀索引和索引选择性: -

2016-12-19 19:54:05 208

原创 Linux中基本操作命令

一、文件系统的管理 tips:输入命令的时候要常用tab键来补全ls 查看目录信息 ( ls / ) ls -l 等价于 ll pwd 查看当前所处的路径 cd 切换目录 (cd /) ,如果不带参数则切换到用户主目录 ~mkdir 创建文件夹 rmdir 删除空文件夹 (只能删除空文件夹) rm -r /a/b (删除非空文件夹)创建文件

2016-12-18 13:38:13 237

原创 Servlet

servlet 是运行在 Web 服务器中的小型 Java 程序(即:服务器端的小应用程序)。servlet 通常通过 HTTP(超文本传输协议)接收和响应来自 Web 客户端的请求。 1.1、编写一个servlet程序: a、写一个java类,实现servlet接口 b、修改web.xml文件,给servlet提供一个可访问的URI地址 部署应用到tomcat服务器 d、测试

2016-12-15 16:56:17 243

原创 Leetcode225. Implement Stack using Queues

该题和232题类似,思想上差不多232题 原题 Implement the following operations of a stack using queues.push(x) – Push element x onto stack. pop() – Removes the element on top of the stack. top() – Get the top element.

2016-12-12 16:41:05 204

原创 Schema与数据类型优化

选择优化的数据类型更小的通常更好,更快,占用的更少的磁盘、内存和CPU缓存,并且需要的CPU周期更短简单就好尽量避免null,因为使用null对于索引、索引统计、值比较都是比较麻烦整数类型

2016-12-12 11:23:01 196

原创 Leetcode232. Implement Queue using Stacks

原题 Implement the following operations of a queue using stacks.push(x) – Push element x to the back of queue. pop() – Removes the element from in front of queue. peek() – Get the front element. empt

2016-12-12 09:46:21 220

原创 Leetcode20. 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 valid b

2016-12-10 19:13:18 145

原创 Java中栈的用法

Stack 类表示后进先出(LIFO)的对象堆栈。它通过五个操作对类 Vector 进行了扩展 ,允许将向量视为堆栈。它提供了通常的 push 和 pop 操作,以及取堆栈顶点的 peek 方法、测试堆栈是否为空的 empty 方法、在堆栈中查找项并确定到堆栈顶距离的 search 方法。 首次创建堆栈时,它不包含项

2016-12-10 19:07:54 1561

转载 HashMap Hashtable区别

http://blog.csdn.net/java2000_net/article/details/2512510 http://blog.csdn.net/shohokuf/article/details/3932967 我们先看2个类的定义[java] view plain copypublic class Hashtable extends Dictionary

2016-12-09 22:16:05 165

原创 Leetcode162. Find Peak Element

原题 A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks, in that

2016-12-08 10:48:56 141

原创 Leetcode263. Ugly Number

原题 Write a program to check whether a given number is an ugly number.Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For example, 6, 8 are ugly while 14 is not ugly since i

2016-12-07 14:25:50 146

原创 会话追踪中的Cookie和Session机制的区别

存取方式 Cookie只能保存ASCII字符串,如需其他需要进行UTF-8,GBK或是BASE64等转换,不能直接存取java对象。 Session可以存取任何类型的数据,可以看做是一个Java 容器类。 隐私安全 Cookie存储在客户端浏览器,对客户端可见,所以敏感信息不要写到Cookie中,可以加密存储, 但是Session是放在服务器上的,可以存任何隐私。 有效期 如果想长期

2016-12-06 22:16:12 219

原创 Java连接数据库JDBC

一、注册Mysql驱动 二、获取Connection 三、创建Statement 四、查询数据库返回ResultSet对象 五、遍历ResultSet输出数据 六、关闭ResultSet、关闭Statement、关闭Connection

2016-12-06 17:20:40 157

原创 Leetcode165. Compare Version Numbers

原题 Compare two version numbers version1 and version2. If version1 > version2 return 1, if version1 < version2 return -1, otherwise return 0.You may assume that the version strings are non-empty and c

2016-12-06 16:37:41 225

转载 【转】Java String.split()用法小结

在java.lang包中有String.split()方法,返回是一个数组我在应用中用到一些,给大家总结一下,仅供大家参考:1、如果用“.”作为分隔的话,必须是如下写法,String.split(“\.”),这样才能正确的分隔开,不能用String.split(“.”);2、如果用“|”作为分隔的话,必须是如下写法,String.split(“\|”),这样才能正确的分隔开,不能用String.sp

2016-12-06 15:43:52 278

原创 Leetcode28. Implement strStr()

原题 Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack. 大意 判断字符串中是否包含另一个字符串,如果包含的话则返回字符串第一次出现的地方;如果没有包含的话,则返回-1 思路 本来想双层遍历字符

2016-12-06 14:23:19 170

空空如也

空空如也

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

TA关注的人

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