OneCoder


  • 首页

  • 归档

  • 标签

  • 关于

  • 搜索

Netty4自学笔记 (3) - Netty NIO Server & Client 样例说明

发表于 2018-08-13 | 阅读次数

更新节奏缓慢,因为每晚学习注意力不够集中,学习进展缓慢。本还给自己找了一大堆其他理由,但摸着良心问自己,似乎只有这个理由说的通。

想搞懂的太多,却始终没搞明白。先看一个用Netty编写的NIO Server的样例。

阅读全文 »

Netty4自学笔记 (2) - Java NIO

发表于 2018-07-24 | 阅读次数

距离上一篇博文已经过去了半个多月。这期间有一周多的时间用在了准备单位举办的英语竞赛上。余下的时间沉迷于陪孩子玩耍和睡觉,日复一日。

当然,我也抽空学习了Java NIO(None-Blocking / New IO) 一些知识,现总结如下。

Java的非阻塞IO的原理是采用了操作系统的多路复用器机制,即在一个通道(channel)上,注册一个事件选择器(selector)及各种事件(读、写等),当有事件到达时,事件选择器返归对应的事件,然后可对事件进行处理,这样即可实现在单一线程上对来自不同客户的请求进行交替处理,服务端处理返回后即可处理下一事件,而不会受制于客户端的响应速度,提高了并发访问的效率。

阅读全文 »

Netty4自学笔记 (1) - Java BIO

发表于 2018-07-06 | 阅读次数

2012年,由于项目的需要我第一次接触到了Netty,当时Netty还处于3.x版本。我用十几篇博文记录了自己自学Netty的过程,虽然内容浅薄,但没想到被各处转载,我想主要是因为当时Netty的资料确实较少的缘故。

五六年过去了,Netty早已发展到了4.x系列,好奇也好,求知也罢,我打算重学Netty,虽然严格来说,我已不是IT从业人员,但我仍希望保留对技术的热爱与追求。

学习Netty,就免不了先去了解Java中的几种通信模型。我不想先去学习很多概念,单刀直入,就先从最容易理解的BIO(阻塞I/O)学起。

阅读全文 »

LeetCode Implement Queue Using Stacks

发表于 2018-06-08 | 阅读次数

Problem

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() -- Return whether the queue is empty.

Example:

MyQueue queue = new MyQueue();

queue.push(1);
queue.push(2);  
queue.peek();  // returns 1
queue.pop();   // returns 1
queue.empty(); // returns false

Notes:

You must use only standard operations of a stack – which means only push to top, peek/pop from top, size, and is empty operations are valid. Depending on your language, stack may not be supported natively. You may simulate a stack by using a list or deque (double-ended queue), as long as you use only standard operations of a stack. You may assume that all operations are valid (for example, no pop or peek operations will be called on an empty queue).false

即用stack来实现queue

阅读全文 »

LeetCode Power of Two

发表于 2018-06-07 | 阅读次数

Problem

Given an integer, write a function to determine if it is a power of two.

Example 1:

Input: 1
Output: true 
Explanation: 2^0 = 1

Example 2:

Input: 16
Output: true
Explanation: 2^4 = 16

Example 3:

Input: 218
Output: false

判断一个整数是否是2的幂次方

阅读全文 »

LeetCode Invert Binary Tree

发表于 2018-06-07 | 阅读次数

Problem

Invert a binary tree.

Example:

Input:

     4
   /   \
  2     7
 / \   / \
1   3 6   9
Output:

     4
   /   \
  7     2
 / \   / \
9   6 3   1

对树进行完全的左右节点交换

阅读全文 »

LeetCode Implement Stack using Queue

发表于 2018-06-05 | 阅读次数

Problem

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 whether the stack is empty. Example:

MyStack stack = new MyStack();

stack.push(1);
stack.push(2);  
stack.top();   // returns 2
stack.pop();   // returns 2
stack.empty(); // returns false

Notes:

You must use only standard operations of a queue – which means only push to back, peek/pop from front, size, and is empty operations are valid. Depending on your language, queue may not be supported natively. You may simulate a queue by using a list or deque (double-ended queue), as long as you use only standard operations of a queue. You may assume that all operations are valid (for example, no pop or top operations will be called on an empty stack).

利用队列实现栈,这个题真是挺奇怪的。。。所以好像评价不高。。

阅读全文 »

LeetCode Contains Duplicate II

发表于 2018-06-05 | 阅读次数

Problem

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 absolute difference between i and j is at most k.

Example 1:

Input: nums = [1,2,3,1], k = 3
Output: true

Example 2:

Input: nums = [1,0,1,1], k = 1
Output: true

Example 3:

Input: nums = [1,2,3,1,2,3], k = 2
Output: false

给定一个整数数组和一个整数 k,判断数组中是否存在两个不同的索引 i 和 j,使得 nums [i] = nums [j],并且 i 和 j 的差的绝对值最大为 k。

阅读全文 »

LeetCode Contains Duplicate

发表于 2018-06-05 | 阅读次数

Problem

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 distinct.

Example 1:

Input: [1,2,3,1]
Output: true

Example 2:

Input: [1,2,3,4]
Output: false

Example 3:

Input: [1,1,1,3,3,4,3,2,4,2]
Output: true

即判断数据中是否有重复元素

阅读全文 »

LeetCode Reverse Linked List

发表于 2018-06-04 | 阅读次数

Problem

Reverse a singly linked list.

Example:

Input: 1->2->3->4->5->NULL
Output: 5->4->3->2->1->NULL

Follow up:

A linked list can be reversed either iteratively or recursively. Could you implement both?

即反转链表,建议采用递归和迭代两种方式。

阅读全文 »
1 2 … 30
LiHongZhe

LiHongZhe

onecoder's blog.

300 日志
8 分类
RSS
Creative Commons
Links
  • 酷壳
  • 酸菜鱼
  • 私塾在线学习网
  • 煮酒品茶
  • 点滴技术博客
  • 思考者日记网·束洋洋
  • 开源视窗
  • 小弟子的网络之路
  • 寄存心–移动开发
  • TicmyBlog
  • 中国程序员人才网
  • 图表秀-在线图表制作
  • IT热血青年
© 2012 - 2018 LiHongZhe
由 Jekyll 强力驱动
主题 - NexT.Muse
本站访客数 人次 本站总访问量 次