- 博客(77)
- 资源 (1)
- 收藏
- 关注
原创 数据结构——散列表
什么是散列表 散列表也叫做哈希表(hash table),这种数据结构提供了键和值的映射关系。根据key可以快速的查找他所匹配的value,时间复杂度接近于O(1)。散列表的实现 散列表本质上就是一个数组,这也是为啥散列表为啥查找速度快。 数组的下标是0,1,2,3....这样的,散列表的key一般都是字符串类型的,所以我们需要一个“中转站”,通...
2019-12-15 17:58:49
357
转载 浅谈CSRF攻击方式
转自:http://www.cnblogs.com/hyddd/archive/2009/04/09/1432744.html一.CSRF是什么? CSRF(Cross-site request forgery),中文名称:跨站请求伪造,也被称为:one click attack/session riding,缩写为:CSRF/XSRF。二.CSRF可以做什么?
2017-02-08 11:43:15
267
原创 简单工厂模式
定义:简单工厂模式是类的创建模式,又叫做静态工厂方法(Static Factory Method)模式。简单工厂模式是由一个工厂类根据传入的参量决定创建出哪一种产品类的实例。优点:工厂类是整个模式的关键:包含了必要的逻辑判断,根据外界给定的信息,决定究竟应该创建哪个具体类的对象。通过使用工厂类,外界可以从直接创建具体产品对象的尴尬局面摆脱出来,仅仅需要负责“消费”对象就可以了。而不
2016-12-29 15:14:26
268
原创 单例模式
定义:保证一个类仅有一个实例,并提供一个访问它的全局访问点。单例模式的优缺点:优点:1. 改进系统的设计2. 是对全局变量的一种改进缺点:1. 难于调试2. 隐藏的依赖关系3. 无法用错误类型的数据覆写一个单例php示例代码:<?php/** * 单例模式 */class User{ //静
2016-12-28 11:57:46
231
原创 linux下Memcache服务器端的安装
1、需要两个安装包memcache安装包,可到官网下载(http://memcached.org/);libevent安装包,官网(http://monkey.org/~provos/libevent/)2、把安装包上传到 home目录下cd /home#解压安装包tar -zxvf memcached-1.4.5.tar.gztar -zxvf libevent-1.
2016-04-25 16:07:01
349
转载 memcache适用和不适用场景
适用memcached的业务场景:1)如果网站包含了访问量很大的动态网页,因而数据库的负载将会很高。由于大部分数据库请求都是读操作,那么memcached可以显著地减小数据库负载。2)如果数据库服务器的负载比较低但CPU使用率很高,这时可以缓存计算好的结果( computed objects )和渲染后的网页模板(enderred templates)。3)利用memcached可以缓
2016-04-22 15:34:25
329
转载 全面剖析Smarty缓存机制
今天主要全面总结下Smarty模板引擎中强大的缓存机制,缓存机制有效减少了系统对服务器的压力,而这也是很多开发者喜欢Smarty的原因之一,由于篇幅较大,便于博友阅读,这篇文章将剖析Smarty缓存的几种方式,下篇文章着重讲解下设置缓存及清除缓存的技巧方法(其中包含缓存集合方法)。一、Smarty缓存的几种方式缓存机制中,分为全局缓存、部分缓存、局部缓存三种方式,后面会一一讲述,下面是
2016-04-20 18:53:01
223
转载 php中web上传文件的原理及如何限制上传文件的大小及格式
一、限制上传文件的大小move_uploaded_file(); 利用php的文件函数来实现上传这段代码分为两个文件,一个为upload.html,一个是upload.phpupload.html 其中,请注意 这是一个标签,我们要实现文件的上传,必须指定为multipart/form-data,否则服务器将不知道要干什么。表单中e
2016-03-17 09:33:25
3749
原创 微信浏览器自带的返回上一页的停留位置
我们做过微信的应该都知道,微信自带的返回上一页,就是重新打开页面。并不是返回历史页面。我们PC端的浏览器是返回历史页面。点击返回页面之后 上一个页面的scrollTop还是之前没有进入新页面的位置。解决办法:利用sessionStorage HTML5本地存储 进行存储位置scrollTop以及加载了多少次ajax次数 微信返回上一页(当前页面)之后。就会onload一下。设置最后一次sc
2016-02-04 12:17:38
17910
1
原创 Longest Palindromic Substring 最长回文
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.1、动态规划class Soluti
2015-12-21 21:27:33
231
原创 Longest Palindromic Substring 最长回文字符串
Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring.1、动态规划class Solu
2015-12-21 21:18:49
235
原创 nginx与apache的区别
nginx 相对 apache 的优点: 轻量级,同样起web 服务,比apache 占用更少的内存及资源抗并发,nginx 处理请求是异步非阻塞的,而apache 则是阻塞型的,在高并发下nginx 能保持低资源低消耗高性能高度模块化的设计,编写模块相对简单社区活跃,各种高性能模块出品迅速啊apache 相对nginx 的优点: rewrite ,比nginx 的re
2015-12-14 16:35:43
233
转载 处理百万级以上的数据提高查询速度的方法
处理百万级以上的数据提高查询速度的方法: 1.应尽量避免在 where 子句中使用!=或 2.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 order by 涉及的列上建立索引。 3.应尽量避免在 where 子句中对字段进行 null 值判断,否则将导致引擎放弃使用索引而进行全表扫描,如: select id from t where num is n
2015-12-14 15:38:29
2706
原创 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 sinc
2015-12-11 19:16:19
171
原创 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 has only o
2015-12-11 19:06:25
184
原创 Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]/** * Definition for
2015-12-11 18:58:35
264
原创 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?思路:找到链表中点,拆分后,逆转后半个链表,然后两个链表同时顺序遍历一次。/** * Definition for singly-linked list.
2015-12-11 18:33:47
163
原创 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.empty(
2015-12-11 17:11:21
174
原创 Power of Two
Given an integer, write a function to determine if it is a power of two.class Solution {public: bool isPowerOfTwo(int n) { if(n == 0 ) return false; while(n != 1){
2015-12-11 17:01:30
177
原创 Summary Ranges
Given a sorted integer array without duplicates, return the summary of its ranges.For example, given [0,1,2,4,5,7], return ["0->2","4->5","7"].class Solution {public: vector summaryRanges
2015-12-11 16:50:41
237
原创 Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1/** * Definition for a binary tree node. * struct TreeNode { * int
2015-12-11 16:14:50
189
原创 Implement Stack using Queues
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.empty() -- Return whet
2015-12-11 16:01:39
184
原创 Rectangle Area
Find the total area covered by two rectilinear rectangles in a 2D plane.Each rectangle is defined by its bottom left corner and top right corner as shown in the figure.Assume that the total ar
2015-12-11 15:34:48
218
原创 Contains Duplicate II
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the difference between i and jis at most k.class
2015-12-11 15:11:07
241
原创 Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element is
2015-12-11 14:48:47
178
原创 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
2015-12-11 14:30:53
146
转载 Count Primes
Description:Count the number of prime numbers less than a non-negative number, n.我们知道2是最小的质数,那么2的倍数均不为质数(因为它们可以分解为一个数*2),所以我们可以将小于n的数中2的倍数,全部排除掉。排除掉2的整数倍后,剩下的数中大于2的最小的数就是下一个质数,也就是3.同样我们可以排
2015-12-11 13:02:29
394
原创 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/** * Definition for si
2015-12-11 11:18:45
188
原创 Happy Number
Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares o
2015-12-11 11:07:56
192
原创 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 adjacent house
2015-12-11 10:44:52
159
原创 Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary representation 00000000
2015-12-11 10:27:39
172
原创 Reverse Bits
Reverse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as001110010111
2015-12-11 10:16:38
158
原创 Rotate Array
Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note:Try to come up as many solutions as you ca
2015-12-10 17:30:36
159
转载 Factorial Trailing Zeroes
Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.Credits:Special thanks to @ts for adding this problem and creating all
2015-12-10 17:05:45
149
原创 Excel Sheet Column Number
Related to question Excel Sheet Column TitleGiven a column title as appear in an Excel sheet, return its corresponding column number.For example: A -> 1 B -> 2 C -> 3 ... Z ->
2015-12-10 16:36:21
176
原创 Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element al
2015-12-10 10:58:48
179
原创 Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> AB 实际上就是把10进制
2015-12-10 10:30:32
201
原创 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
2015-12-10 10:06:08
214
原创 Intersection of Two Linked Lists
Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘
2015-12-09 16:10:54
167
原创 Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get
2015-12-09 15:51:24
175
Asp.net中生成验证码
2013-04-21
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人