自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 Memcached缓存

Memcached是免费的,开源的,高性能的,分布式内存对象的缓存系统(键/值字典),旨在通过减轻数据库负载加快动态Web应用程序的使用。 Memcached是由布拉德·菲茨帕特里克(Brad Fitzpatrick)在2003年为LiveJournal 开发的,现在有很多知名网站都在使用,包括:Netlog, Facebook, Flickr, Wikipedia, Twitter, Yo

2016-03-30 15:48:55 242

原创 Redis缓存

Redis是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。从2010年3月15日起,Redis的开发工作由VMware主持。从2013年5月开始,Redis的开发由Pivotal赞助。 Redis是一个开源,先进的key-value存储,并用于构建高性能,可扩展的Web应用程序的完美解决方案。 Redis从

2016-03-30 15:48:06 229

原创 MongoDB导入导出基本操作

导入导出数据命令: mongoexport、mongoimport:导出导入表(-c)、或字段; mongodump、mongorestore:导出导入(所有或单个)数据库(-d);options: { -d: 数据库名, -c: 数据表名(collection), -o: 导出的路径,或文件名(.dat), --file: 导入文件, --csv: 表明导出 csv 格式,默认是

2016-03-30 15:47:08 286

原创 nodejs express

get方法 —— 根据请求路径来处理客户端发出的GET请求。 格式:app.get(path,function(request, response)); path为请求的路径,第二个参数为处理请求的回调函数,有两个参数分别是request和response,代表请求信息和响应信息。 如下示例: var express = require('express')

2016-03-02 00:18:24 219

原创 nodejs Util

inspect函数的基本用法 util.inspect(object,[showHidden],[depth],[colors])是一个将任意对象转换为字符串的函数,通常用于调试和错误输出。它至少接受一个参数object,即要转换的对象 var util = require('util'); var result = util.inspect(object); console.lo

2016-03-01 22:01:25 217

原创 nodejs String

stringify函数的基本用法 stringify函数的作用就是序列化对象,也就是说将对象类型转换成一个字符串类型(默认的分割符("&")和分配符("=")) 例1:querystring.stringify("对象") var querystring= require('querystring'); var result = querystring.stringify({foo

2016-03-01 21:59:11 1351

原创 nodejsPath

normalize函数的基本用法 normalize函数将不符合规范的路径经过格式化转换为标准路径,解析路径中的.与..外,还能去掉多余的斜杠。 如下示例: var path = require('path');   var data = path.normalize('/path///normalize/hi/..'); console.log(data); 运行结果

2016-03-01 21:55:47 235

原创 203. Remove Linked List Elements

public class Solution {     public ListNode removeElements(ListNode head, int val) {         ListNode fakeHead = new ListNode(-1);         fakeHead.next = head;         ListNode curr = head, p

2016-02-29 10:19:14 110

原创 290. Word Pattern

public class Solution {     public boolean wordPattern(String pattern, String str) {         String[]strs=str.split(" ");         if(pattern.length()!=strs.length)return false;         Mapmap=new

2016-02-29 10:18:55 134

原创 299. Bulls and Cows

public class Solution {     public String getHint(String secret, String guess) {         int bulls=0;         int cows=0;         int [] nums=new int [10];         for(int i=0;i             int

2016-02-29 10:18:37 128

原创 nodejsURL

url处理 parse函数的基础用法 parse函数的作用是解析url,返回一个json格式的数组,请看如下示例: var url = require('url'); url.parse('http://www.baidu.com'); 运行结果: { protocol: 'http:',   slashes: null,   auth: null,   host: nu

2016-02-29 10:11:32 154

原创 nodejsIO

文件I/O,写入是必修课之一。fs模块提供writeFile函数,可以异步的将数据写入一个文件, 如果文件已经存在则会被替换。用法如下: 例:fs.writeFile(filename, data, callback) var fs= require("fs");   fs.writeFile('test.txt', 'Hello Node', function (err)

2016-02-29 10:09:35 229

原创 nodejs进程

process是一个全局内置对象,可以在代码中的任何位置访问此对象,这个对象代表我们的node.js代码宿主的操作系统进程对象。 使用process对象可以截获进程的异常、退出等事件,也可以获取进程的当前目录、环境变量、内存占用等信息,还可以执行进程退出、工作目录切换等操作。 当我们想要查看应用程序当前目录时,可以使用cwd函数,使用语法如下: process.cwd

2016-02-29 10:06:21 329

原创 nodejs

回调函数 由于node是一个异步事件驱动的平台,所以在代码中我们经常需要使用回调函数。下面是回调函数应用的经典示例: setTimeout(function(){ console.log('callback is called'); },2000); 我们传给setTimeout函数传入了一个匿名函数和一个调用时间2000(毫秒),运行程序后等待2秒,可以看到输出

2016-02-26 00:05:49 172

原创 20. Valid Parentheses

public class Solution {     public boolean isValid(String s) {         Stack stack = new Stack();         for(int i = 0; i             if(s.charAt(i) == '(' || s.charAt(i) == '[' || s.charAt(i) ==

2016-02-26 00:03:33 213

原创 205. Isomorphic Strings

public class Solution {     public boolean isIsomorphic(String s, String t) {         if(s == null || s.length()         HashMap map = new HashMap();         for(int i = 0 ; i             char a

2016-02-26 00:02:36 203

原创 58. Length of Last Word

public class Solution {     public int lengthOfLastWord(String s) {         return s.trim().length()-s.trim().lastIndexOf(" ")-1;     } }

2016-02-26 00:02:03 131

原创 190. Reverse Bits

public class Solution {     // you need treat n as an unsigned value     public int reverseBits(int n) {     int result = 0;     for (int i = 0; i         result += n & 1;         n >>>=1;   //

2016-02-26 00:01:27 172

原创 223. Rectangle Area

public class Solution {     public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) {         int s1=(D-B)*(C-A);         int s2=(G-E)*(H-F);         int l=Math.max(A,E);  

2016-02-25 23:59:07 178

原创 219. Contains Duplicate II

public class Solution {     public boolean containsNearbyDuplicate(int[] nums, int k) {         Mapmap=new HashMap         for(int i=0;i             if(!map.containsKey(nums[i])){                

2016-02-25 23:58:37 151

原创 36. Valid Sudoku

public class Solution {     public boolean isValidSudoku(char[][] board) {         List>rl=new ArrayList>();         List>cl=new ArrayList>();         List>sl=new ArrayList>();                 

2016-02-25 23:58:01 149

原创 88. Merge Sorted Array

public class Solution {     public void merge(int[] nums1, int m, int[] nums2, int n) {                 int cnt=m+n-1;         int i=m-1;         int j=n-1;         while(i>=0&&j>=0){          

2016-02-19 01:36:03 185

原创 111. Minimum Depth of Binary Tree

public class Solution {     public int minDepth(TreeNode root) {         if(root==null)return 0;         int l=minDepth(root.left);         int r=minDepth(root.right);         if(l==0||r==0)retur

2016-02-19 01:35:12 135

原创 225. Implement Stack using Queues

class MyStack {     Queue q = new LinkedList();     // Push element x onto stack.     public void push(int x) {         q.add(x);     }     // Removes the element on top of the stack.  

2016-02-17 00:42:41 268

原创 9. Palindrome Number

判断回文串 第一个和最后一个比 public class Solution {     public boolean isPalindrome(int x) {         String a=Integer.toString(x);         if(a.length()         for(int i=0,j=a.length()-1;i             if(a

2016-02-17 00:42:02 140

原创 112. Path Sum

public class Solution {     public boolean hasPathSum(TreeNode root, int sum) {         if(root==null)return false;         if(root.left==null&&root.right==null&&root.val==sum)return true;        

2016-02-17 00:41:11 150

原创 26. Remove Duplicates from Sorted Array

public class Solution {     public int removeDuplicates(int[] nums) {         int cnt=0;         if(nums.length==0)return cnt;         if(nums.length==1)return 1;         for(int i=0;i          

2016-02-16 01:53:13 233

原创 27. Remove Element

public class Solution {     public int removeElement(int[] nums, int val) {         int cnt=0;         for(int i=0;i             if(nums[i]!=val){                 nums[cnt]=nums[i];            

2016-02-16 01:52:45 140

原创 102. Binary Tree Level Order Traversal

public class Solution {     public List> levelOrder(TreeNode root) {         List>res=new ArrayList>();         levelHelper(res,root,0);         return res;     }     public void levelHelper(Lis

2016-02-15 01:51:22 153

原创 107. Binary Tree Level Order Traversal II

public class Solution {     public List> levelOrderBottom(TreeNode root) {         List>res=new ArrayList>();         levelHelper(res,root,0);         return res;     }     public void levelHelp

2016-02-15 01:50:42 159

原创 198. House Robber

子问题每次选不选第一个 public class Solution {     public int rob(int[] nums) {         int a=0;         int b=0;         for(int i=0;i             if(i%2==0){                 a=Math.max(a+nums[i],b);

2016-02-14 01:16:03 138

原创 101. Symmetric Tree

树相关的问题一般都是递归 public class Solution {     public boolean isSymmetric(TreeNode root) {         if(root==null)return true;         return isMirror(root.left,root.right);     }     public boolean is

2016-02-14 01:10:23 243

原创 110. Balanced Binary Tree

递归方法  public class Solution {     private boolean ans=true;     public boolean isBalanced(TreeNode root) {         maxDepth(root);         return ans;     }     public int maxDepth(TreeNode roo

2016-02-14 01:08:55 213

原创 232. Implement Queue using Stacks

class MyQueue {     // Push element x to the back of queue.     Stack s1 = new Stack     Stack s2 = new Stack     public void push(int x) {         s1.push(x);     }     // Removes the

2016-02-13 00:16:07 189

原创 231. Power of Two

一直除2 public class Solution {     public boolean isPowerOfTwo(int n) {         if(n==0)return false;         if(n==1)return true;         if(n%2==1)return false;         while(n%2==0){          

2016-02-13 00:10:34 125

原创 326. Power of Three

用math.log求3为底的对数 public class Solution {     public boolean isPowerOfThree(int n) {          double res = Math.log(n)/Math.log(3);         return Math.abs(res - Math.rint(res))     } }

2016-02-13 00:08:39 200

原创 202. Happy Number

主要是用一个set验证所得数会不会循环  每出现一个新数 放入set 如果出现过就说明有循环 退出 public class Solution {     public boolean isHappy(int n) {         if(n         long ln = n;         Set set = new HashSet();                 

2016-02-12 00:44:44 131

原创 263. Ugly Number

一个数是235的倍数 先除2 然后3 然后5  public class Solution {     public boolean isUgly(int num) {         if(num==0){             return false;         }         if(num==1){             return true;      

2016-02-12 00:41:52 148

原创 83. Remove Duplicates from Sorted List

如果第i个和i+1的值相等 next跳过下一个。 public class Solution {     public ListNode deleteDuplicates(ListNode head) {         if(head==null){             return null;         }         ListNode node=head;    

2016-02-12 00:39:34 125

原创 70. Climbing Stairs

动态规划  最后一步走1步还是两步 public class Solution {     public int climbStairs(int n) {         if(n==1){             return 1;         }         if(n==2){             return 2;         }         int l

2016-02-12 00:37:40 204

空空如也

空空如也

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

TA关注的人

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