06 2018 档案

摘要:一闪一闪亮晶晶,满天都是小星星,牛牛晚上闲来无聊,便躺在床上数星星。 牛牛把星星图看成一个平面,左上角为原点(坐标为(1, 1))。现在有n颗星星,他给每颗星星都标上坐标(xi,yi),表示这颗星星在第x行,第y列。 现在,牛牛想问你m个问题,给你两个点的坐标(a1, b1)(a2,b2),表示一个 阅读全文
posted @ 2018-06-26 16:28 immjc 阅读(610) 评论(0) 推荐(0)
摘要:一维前缀和 主要用于在O(1)时间内找出A[i]+A[i+1]+...+A[j]的和 原理: 用sum[i]表示A[1]+A[2]+...+A[i],则sum[0] = 0, sum[1] = A[1], sum[2] = A[1]+A[2]; sum[3]=A[1]+A[2]+A[3]; 则A[i 阅读全文
posted @ 2018-06-26 16:22 immjc 阅读(167) 评论(0) 推荐(0)
摘要: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 阅读全文
posted @ 2018-06-19 22:06 immjc 阅读(113) 评论(0) 推荐(0)
摘要:题目描述 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位置不变。 思路 题目要求不改变调整前后奇偶元素之间的相对位置。所以可以借鉴冒泡的思路。 即:当遍历到元素x为偶数时,将其调整到 阅读全文
posted @ 2018-06-10 11:17 immjc 阅读(149) 评论(0) 推荐(0)
摘要:Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. Note: The algorithm should run in linear time and in O(1) spa 阅读全文
posted @ 2018-06-08 22:27 immjc 阅读(137) 评论(0) 推荐(0)
摘要:Nginx事件模型 异步非阻塞 Nginx采取异步非阻塞的方式处理请求。 处理请求流程:收到请求,建立连接,接收数据,发送数据。 如果采用阻塞调用,会陷入内核等待,在单进程的nginx下这样cpu就会空闲,没法充分使用。 采用非阻塞调用,会在事件没有准备好时,返回EAGAIN来通知,此时线程还可以做 阅读全文
posted @ 2018-06-08 16:45 immjc 阅读(521) 评论(0) 推荐(0)
摘要:Nginx进程模型 Nginx是以多进程的方式来工作的,Nginx在启动之后,会有一个master进程和与多个worker进程(worker进程数与CPU核心数相同,以防止多进程之间抢占资源)。 master进程 master进程主要用于管理调度worker进程。 master的主要工作如下: 接收 阅读全文
posted @ 2018-06-08 16:31 immjc 阅读(164) 评论(0) 推荐(0)
摘要:函数中的数组 1. p是一个数组,是一个局部变量,说明这个函数执行完毕之后p数组中的值都被销毁了 如果单独使用p,则p表示这块数组的首地址。函数返回值按值传递是p,仅仅传递p的地址,而p数组中的内容都被销毁了。 2. 常量区的字符不能修改。 3. 正确,helloworld存在于常量区。不会随着函数 阅读全文
posted @ 2018-06-07 11:19 immjc 阅读(1781) 评论(0) 推荐(0)
摘要:Given a string S and a character C, return an array of integers representing the shortest distance from the character C in the string. Example 1: Note 阅读全文
posted @ 2018-06-07 10:13 immjc 阅读(130) 评论(0) 推荐(0)
摘要:We are to write the letters of a given string S, from left to right into lines. Each line has maximum width 100 units, and if writing a letter would c 阅读全文
posted @ 2018-06-07 09:43 immjc 阅读(162) 评论(0) 推荐(0)
摘要:International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: "a"maps to ".-", "b" maps 阅读全文
posted @ 2018-06-07 09:29 immjc 阅读(139) 评论(0) 推荐(0)
摘要:A website domain like "discuss.leetcode.com" consists of various subdomains. At the top level, we have "com", at the next level, we have "leetcode.com 阅读全文
posted @ 2018-06-07 09:15 immjc 阅读(201) 评论(0) 推荐(0)
摘要:We are given the head node root of a binary tree, where additionally every node's value is either a 0 or a 1. Return the same tree where every subtree 阅读全文
posted @ 2018-06-06 15:49 immjc 阅读(124) 评论(0) 推荐(0)
摘要:Given a binary matrix A, we want to flip the image horizontally, then invert it, and return the resulting image. To flip an image horizontally means t 阅读全文
posted @ 2018-06-06 15:32 immjc 阅读(116) 评论(0) 推荐(0)
摘要:In a 2 dimensional array grid, each value grid[i][j] represents the height of a building located there. We are allowed to increase the height of any n 阅读全文
posted @ 2018-06-06 15:18 immjc 阅读(141) 评论(0) 推荐(0)
摘要:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted f 阅读全文
posted @ 2018-06-06 11:50 immjc 阅读(118) 评论(0) 推荐(0)
摘要:Given an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. 阅读全文
posted @ 2018-06-06 11:35 immjc 阅读(91) 评论(0) 推荐(0)
摘要:小Q正在给一条长度为n的道路设计路灯安置方案。 为了让问题更简单,小Q把道路视为n个方格,需要照亮的地方用'.'表示, 不需要照亮的障碍物格子用'X'表示。 小Q现在要在道路上设置一些路灯, 对于安置在pos位置的路灯, 这盏路灯可以照亮pos - 1, pos, pos + 1这三个位置。 小Q希 阅读全文
posted @ 2018-06-05 11:53 immjc 阅读(161) 评论(0) 推荐(0)
摘要:小Q得到一个神奇的数列: 1, 12, 123,...12345678910,1234567891011...。 并且小Q对于能否被3整除这个性质很感兴趣。 小Q现在希望你能帮他计算一下从数列的第l个到第r个(包含端点)有多少个数可以被3整除。 遍历从a到b。如果该值可以除3余1,说明该数不能被整除 阅读全文
posted @ 2018-06-05 11:42 immjc 阅读(167) 评论(0) 推荐(0)
摘要:One way to serialize a binary tree is to use pre-order traversal. When we encounter a non-null node, we record the node's value. If it is a null node, 阅读全文
posted @ 2018-06-04 12:09 immjc 阅读(144) 评论(0) 推荐(0)
摘要:Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or 阅读全文
posted @ 2018-06-04 11:30 immjc 阅读(125) 评论(0) 推荐(0)
摘要:Serialization is the process of converting a data structure or object into a sequence of bits so that it can be stored in a file or memory buffer, or 阅读全文
posted @ 2018-06-04 11:23 immjc 阅读(142) 评论(0) 推荐(0)
摘要:Given a circular array (the next element of the last element is the first element of the array), print the Next Greater Number for every element. The 阅读全文
posted @ 2018-06-04 09:12 immjc 阅读(103) 评论(0) 推荐(0)
摘要:You are given two arrays (without duplicates) nums1 and nums2 where nums1’s elements are subset of nums2. Find all the next greater numbers for nums1' 阅读全文
posted @ 2018-06-04 08:36 immjc 阅读(113) 评论(0) 推荐(0)
摘要:1. 事务 它是一个操作序列,这些操作要么都执行,要么都不执行。它是一个不可分割的工作单位。 2. ACID 事务具有四个特性:原子性,一致性,隔离性,持久性。 原子性 指事务是一个不可分割的工作单位,事务中的操作要么都发生,要么都不发生 数据库管理系统默认情况下一条SQL就是一个单独的事务,事务是 阅读全文
posted @ 2018-06-03 22:21 immjc 阅读(148) 评论(0) 推荐(0)
摘要:静态库 1. 静态库对函数库的链接是在编译时期完成的 2. 程序在运行时与函数库再无瓜葛,移植方便 3. 浪费空间和资源,因为所有相关的目标文件都与牵连的函数库被链接成一个可执行文件 4. 静态库对程序的更新部署和发布都带来麻烦。 动态库 1. 动态库把对一些函数的链接载入推迟到程序运行的时期 2. 阅读全文
posted @ 2018-06-03 12:40 immjc 阅读(308) 评论(0) 推荐(0)
摘要:抽象工厂模式 抽象工厂针对产品族,不针对产品等级结构 产品族:同一产地同一个厂商,功能不同。 产品等级结构:功能相同,但是产地和厂商不同。 阅读全文
posted @ 2018-06-01 11:22 immjc 阅读(219) 评论(0) 推荐(0)
摘要:工厂方法模式 让一个具体的类对应一个工厂。然后把所有工厂进行抽象。通过抽象工厂实现具体的工厂来创建对象。如果需要新增一个类,那么就需要创建一个工厂类来创建对象 优点: 1. 符合开闭原则。是简单工厂改进 2. 实现创建和使用分离 缺点: 1. 类的个数庞大。增加一个具体对象类就需要增加一个对应工厂类 阅读全文
posted @ 2018-06-01 10:59 immjc 阅读(118) 评论(0) 推荐(0)
摘要:简单工厂模式 在工厂类中通过方法(传入参数)来创建对象。 优点: 1. 使客户端与具体实现解耦 2. 对于创建某些创造过程复杂的对象,直接将创建交给工厂 缺点: 1. 新增类需要修改工厂类中代码,不符合开闭原则 2. 工厂类指责过重。需要多个条件判断来创造对象 所以该模式不属于23类设计模式。 参考 阅读全文
posted @ 2018-06-01 10:42 immjc 阅读(127) 评论(0) 推荐(0)