- 博客(86)
- 资源 (2)
- 问答 (9)
- 收藏
- 关注
原创 同步 异步 阻塞 非阻塞
同步和异步关注的是消息通信机制。主要是针对客户端。 同步:当客户端发出一个功能调用时,在没有得到结果之前,该调用不返回。也就是说必须一件一件的事情去做,等一件做完了才能去做下一件。异步:当客户端发出一个功能调用时,这个调用就直接返回了,不管有没有结果。调用处理完成后,被调用者会通过状态、通知和回调来通知调用者。同步异步主要是针对客户端,但是必须配合服务器端才能实现。同步异步是客户端自己控制,但是服
2017-03-29 11:10:47 320
原创 数据库三大范式详解
第一范式1NF 数据库表的每一列都是不可分割的基本数据项,同一列中不能有多个值,即实体中的某个属性不能有多个值或者不能有重复的属性。 如果出现重复的属性,就需要定义一个新的实体,新的实体由重复的属性构成,新的实体和原实体之间是一对多关系。 在任何一个关系型数据库中,第一范式是基本的要求,必须满足。 下面看例子: 上面的数据表是不符合第一范式的,因为进货下面又可以再次划分为数量和单价,
2017-03-27 21:54:25 529
原创 360春招3.25在线编程题解
第一题: 小明同学最近学习了概率论,他了解到数学期望的定义:设X为一个随机变量,X可以取n种不同的取值x1,x2,x3,…,xn。取x1的概率为p1,取x2的概率为p2,以此类推。定义随机变量X的数学期望为:E[X]=x1*p1+x2*p2+…+xn*pn。小明回到家中,他想编程计算数学期望,你能帮助他么?输入第一行一个数n(1<=n<=100),接下来有n行,第i行有两个数xi和pi,xi和pi
2017-03-26 12:23:10 613
原创 leetcode328~Odd Even Linked List
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do it in plac
2017-03-25 11:25:04 372
原创 leetcode160~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 ↘ c1
2017-03-25 10:43:19 497
原创 leetcode234~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?思路: 判断一个链表是否是回文链表,几种解法都会使用到俩指针,用来从中间分割链表。 1 将前部分的链表元素放入数组中,然后在遍历后半部分的链表时,和数据中逆序元素进行比
2017-03-25 09:15:54 561
原创 leetcode237~Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value 3, t
2017-03-25 08:26:25 372
原创 leetcode146~LRU Cache
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.get(key) - Get the value (will always be positive) of the key if the k
2017-03-25 08:24:03 351
原创 leetcode143~Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes’ values.For example, Given {1,2,3,4}, reorder it to {1,4,2,3}
2017-03-24 10:03:24 245
原创 leetcode142~Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.当fast和slow相遇时,slow肯定没有遍历完链表,而fast已经在环内循环了n圈。假设slow走了s步,则fast走了2s步,环长为r
2017-03-24 09:16:38 258
原创 leetcode141~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?解决链表问题的经典做法:使用俩指针fast和slow,判断最后fast是为null还是fast==slow即可。public class LinkedListCycle {
2017-03-24 08:47:35 317
原创 leetcode133. Clone Graph
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ’s undirected graph serialization: Nodes are labeled uniquely.We use # as a separator for each node, an
2017-03-23 16:07:14 286
原创 leetcode138~Copy List with Random Pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list.两种解法,不同的是空间复杂度不同public class CopyListwi
2017-03-23 14:30:47 312
原创 leetcode25~Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.k is a positive integer and is less than or equal to the length of the linked list. If the number of nod
2017-03-23 13:06:30 247
原创 leetcode24~Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example, Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. You may no
2017-03-23 09:45:39 236
原创 jdk8新特性
Jdk8新特性java语言新特性1 lambda表达式Lambda表达式(也称为闭包)是整个Java 8发行版中最受期待的在Java语言层面上的改变,Lambda允许把函数作为一个方法的参数(函数作为参数传递进方法中),或者把代码看成数据:函数式程序员对这一概念非常熟悉。在JVM平台上的很多语言(Groovy,Scala,……)从一开始就有Lambda,但是Java程序员不得不使用毫无新意的匿名
2017-03-21 14:27:29 530
原创 剖析fail-fast机制和ConcurrentModificationException
快速失败,是java集合中的一种错误检测机制。当多个线程对集合进行结构上的改变操作时,就有可能会产生fail-fast机制。例如存在两个线程1和2,线程1通过Iterator在遍历集合中元素时,线程2修改了集合的结构(添加或者删除元素),这个时候就会抛出ConcurrentModificationException异常,从而产生了fail-fast机制。 并发修改异常ConcurrentModif
2017-03-19 19:51:01 314
原创 leetcode19~Remove Nth Node From End of List
Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, the linked lis
2017-03-19 11:28:26 299
原创 leetcode61~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个数进行翻转。 注意:k可以大于链表的长度,需要对链表长度取余p
2017-03-19 11:01:41 240
原创 leetcode82~Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. For example, Given 1->2->3->3->4->4->5, return 1->2->5. Given 1->1->1
2017-03-19 10:24:48 486
原创 leetcode83~Remove Duplicates from Sorted List
Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3. public class RemoveDuplicate
2017-03-19 09:15:03 327
原创 leetcode86~Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x. You should preserve the original relative order of the nodes in each of t
2017-03-16 21:43:22 189
原创 leetcode206~Reverse Linked List
Reverse a singly linked listpublic class ReverseLinkedList { public ListNode reverseList(ListNode head) { if(head==null) return null; ListNode pre = null; while(head!=null)
2017-03-16 20:49:46 209
原创 leetcode92~Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass. For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4, return 1->4->3->2->5->NULL. Note: Given m, n satisfy the fol
2017-03-16 20:45:38 989
原创 leetcode445~Add Two Numbers II
You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return it
2017-03-15 10:59:33 298
原创 leetcode2~Add Two Numbers
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it
2017-03-15 10:54:26 217
原创 leetcode137~Single Number II
Given an array of integers, every element appears three times except for one, which appears exactly once. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could yo
2017-03-12 16:02:00 222
原创 leetcode136~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 using extra
2017-03-12 13:59:10 205
原创 leetcode135~Candy
There are N children standing in a line. Each child is assigned a rating value. You are giving candies to these children subjected to the following requirements: Each child must have at least one c
2017-03-12 13:45:27 250
原创 leetcode134~Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i]. You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to its ne
2017-03-12 10:25:29 214
原创 leetcode73~Set Matrix Zeroes
Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. public class SetMatrixZeroes { //使用set集合存储 public void setZeroes2(int[][] matrix) { if(matrix
2017-03-11 10:50:23 198
原创 leetcode89~Gray Code
The gray code is a binary numeral system where two successive values differ in only one bit. Given a non-negative integer n representing the total number of bits in the code, print the sequence of gra
2017-03-11 09:48:28 233
原创 leetcode70~Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Note: Given n will be a positive
2017-03-11 08:59:45 209
原创 leetcode48~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?public class RotateImage { //先旋转最外面一层,再旋转里面的层 注意:四个角的不应该
2017-03-10 15:18:23 230
原创 leetcode42~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],
2017-03-10 10:56:51 218
原创 leetcode36~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 filled sudoku wh
2017-03-10 09:19:58 246
原创 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. H
2017-03-09 17:09:19 215
原创 leetcode53~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] has
2017-03-09 16:47:33 212
原创 leetcode66~Plus One
Given a non-negative integer represented as a non-empty array of digits, plus one to the integer. You may assume the integer do not contain any leading zero, except the number 0 itself. The digits ar
2017-03-09 16:10:18 294
原创 leetcode119~Pascal's Triangle II
Given an index k, return the kth row of the Pascal’s triangle. For example, given k = 3, Return [1,3,3,1]. public class PascalTriangleII { //这里每到一行,都会有对应的数1了,所以可以直接从前向后遍历 public List<Integer>
2017-03-09 15:45:05 230
kibana5.2.2
2017-03-07
HashMap插入时存在避免尾部遍历之说?
2017-09-19
阻塞队列问题探讨--锁的问题
2017-08-28
quartz单个任务执行时间太长?分布式?
2017-07-12
openstack热迁移问题(奇葩的问题)
2017-06-05
redis中的负载因子问题
2017-05-26
redis主从链 复制问题
2017-05-22
redis快照存储 条件问题
2017-05-22
nginx的静态和动态资源分开处理问题
2017-05-21
两个用户登录,session id问题
2017-05-20
TA创建的收藏夹 TA关注的收藏夹
TA关注的人