![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Java
LTELTY
一句话说完所有事
展开
-
173. Binary Search Tree Iterator
问题实现一个顺序访问有序二叉树的迭代器。Implement an iterator over a binary search tree (BST). Your iterator will be initialized with the root node of a BST.Calling next() will return the next smallest number in the B...原创 2019-04-18 00:55:05 · 125 阅读 · 0 评论 -
178. Rank Scores
Rank ScoresSQL SchemaWrite a SQL query to rank scores. If there is a tie between two scores, both should have the same ranking. Note that after a tie, the next ranking number should be the next co...原创 2019-05-04 21:17:59 · 114 阅读 · 0 评论 -
177. Nth Highest Salary
Write a SQL query to get the nth highest salary from the Employee table.+----+--------+| Id | Salary |+----+--------+| 1 | 100 || 2 | 200 || 3 | 300 |+----+--------+For example, g...原创 2019-05-04 21:28:14 · 211 阅读 · 0 评论 -
151. Reverse Words in a String
Example 1:Input: “the sky is blue”Output: “blue is sky the”Example 2:Input: " hello world! "Output: “world! hello”Explanation: Your reversed string should not contain leading or trailing space...原创 2019-04-24 17:05:37 · 135 阅读 · 0 评论 -
洗牌算法
1. 背景笔试时,遇到一个算法题:差不多是 在n个不同的数中随机取出不重复的m个数。洗牌算法是将原来的数组进行打散,使原数组的某个数在打散后的数组中的每个位置上等概率的出现,刚好可以解决该问题。2. 洗牌算法由抽牌、换牌和插牌衍生出三种洗牌算法,其中抽牌和换牌分别对应Fisher-Yates Shuffle和Knuth-Durstenfeld Shhuffle算法。2.1 Fisher-Y...原创 2019-04-25 11:36:14 · 2186 阅读 · 0 评论 -
链表的快排、归并排序
引言面试被问到了如何对链表进行排序, 快排不敢写,写了个很低效的插入排序。现在整理一下。解法1、链表的归并排序Node* listMergeSort(Node* head)// n list里面节点的个数{ // if (head->next == NULL) //一个元素就返回 if (head->next == NULL) return head; Nod...原创 2019-04-25 18:00:54 · 214 阅读 · 0 评论 -
悲观锁与乐观锁
引言乐观锁对应于生活中乐观的人总是想着事情往好的方向发展,悲观锁对应于生活中悲观的人总是想着事情往坏的方向发展。这两种人各有优缺点,不能不以场景而定说一种人好于另外一种人。悲观锁总是假设最坏的情况,每次去拿数据的时候都认为别人会修改,所以每次在拿数据的时候都会上锁,这样别人想拿这个数据就会阻塞直到它拿到锁(共享资源每次只给一个线程使用,其它线程阻塞,用完后再把资源转让给其它线程)。传统的关系...原创 2019-04-30 18:03:20 · 158 阅读 · 0 评论 -
176. Second Highest Salary
Second Highest SalaryWrite a SQL query to get the second highest salary from the Employee table.+----+--------+| Id | Salary |+----+--------+| 1 | 100 || 2 | 200 || 3 | 300 |+---...原创 2019-05-06 14:21:57 · 132 阅读 · 0 评论 -
175. Combine Two Tables
Combine Two TablesTable: Person+-------------+---------+| Column Name | Type |+-------------+---------+| PersonId | int || FirstName | varchar || LastName | varchar |+-------...原创 2019-05-06 14:29:09 · 88 阅读 · 0 评论 -
168. Excel Sheet Column Title
Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example:1 -> A2 -> B3 -> C...26 -> Z27 -> AA28 -> AB ...Example 1:Input: ...原创 2019-05-06 15:01:38 · 86 阅读 · 0 评论 -
MongoDb学习总结
引言项目在使用 spring-data-mongodb 来操作 Mongo 数据库的过程中,经常会使用到 MongoTemplate 来增删改查我们的数据。而关于插入数据这一块 MongoTemplate 则提供给我们 insert、save 这两个函数。这里简单的介绍下这两者的区别。区别插入重复数据insert: 若新增数据的主键已经存在,则会抛 org.springframework....原创 2019-05-04 21:12:33 · 699 阅读 · 0 评论 -
165. Compare Version Numbers
Compare Version NumbersMedium2671055FavoriteShareCompare two version numbers version1 and version2.If version1 > version2 return 1; if version1 < version2 return -1;otherwise return 0....原创 2019-04-24 16:29:54 · 100 阅读 · 0 评论 -
357. Count Numbers with Unique Digits
Count Numbers with Unique DigitsGiven a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n.Example:Input: 2Output: 91Explanation: The answer should be the tot...原创 2019-04-18 01:16:48 · 81 阅读 · 0 评论 -
数据库的连接池的数量大于活跃中的线程数,即 size > busy, Unable to fetch a connection in 10 seconds
当数据库连接池被打满的时候,经常可以看到这样的报错:Timeout: Pool empty. Unable to fetch a connection in 10 seconds, none available[size:100; busy:15; idle:0; lastwait:10000].在这里,我们可能有个疑问,为什么size是100而busy是15,这不是说还有 100 -...原创 2019-04-22 20:14:04 · 1214 阅读 · 0 评论 -
926. Flip String to Monotone Increasing
A string of '0’s and '1’s is monotone increasing if it consists of some number of '0’s (possibly 0),followed by some number of '1’s (also possibly 0.)We are given a string S of '0’s and '1’s, and we...原创 2019-04-18 11:11:28 · 153 阅读 · 0 评论 -
638. Shopping Offers
In LeetCode Store, there are some kinds of items to sell. Each item has a price.However, there are some special offers, and a special offer consists of one or more different kinds of items with a sal...原创 2019-04-18 12:52:40 · 164 阅读 · 0 评论 -
消息队列
原文:https://github.com/Snailclimb/JavaGuide/blob/master/docs/system-design/data-communication/message-queue.md一 什么是消息队列二 为什么要用消息队列(1) 通过异步处理提高系统性能(削峰、减少响应所需时间)(2) 降低系统耦合性三 使用消息队列带来的一些问题四 JMS VS A...原创 2019-04-27 13:39:23 · 130 阅读 · 0 评论 -
分布式事务与一致性算法Paxos & raft & zab
1.CAP原理要想数据高可用,就得写多份数据写多分数据就会导致数据一致性问题数据一致性问题会引起性能问题2.一致性模型弱一致性最终一致性(一段时间达到一致性)强一致1、2 异步冗余;3是同步冗余3. 扩展服务的方案数据分区: uid % 16数据镜像:让多有的服务器都有相同的数据,提供相当的服务(冗余存储,一般3份为好)4.两种方案的事务问题A向B汇钱,两个用户不在一个...原创 2019-04-27 13:43:23 · 273 阅读 · 0 评论 -
长URL链接转短链接算法
引言最近看到微博的短链接真是很火啊,新浪、腾讯、搜狐等微博网站都加入了短链接的功能。之所以要是使用短链接,主要是因为微博只允许发140 字,如果链接地址太长的话,那么发送的字数将大大减少。短链接的主要职责就是把原始链接很长的地址压缩成只有6 个字母的短链接地址,当我们点击这6 个字母的链接后,我们又可以跳转到原始链接地址。开始以为短链接是按照某种算法把原始链接压缩为短链接,再根据算法从短链接反...原创 2019-04-27 17:29:37 · 11006 阅读 · 2 评论 -
负载均衡三个特性
引言负载均衡设备作为纵跨网络2-7层协议的设备,往往放置在网络设备和应用设备的连接处,对工程师在网络和应用基本知识方面的要求远高于其他设备,所以我们要在基本功能的理解上下更多的功夫。负载均衡设备还有另外一个称呼:4/7层交换机,但它首先是个2-3层交换机,这要求我们首先掌握2-3层的基本知识,然后才是本文介绍的内容。服务器负载均衡有三大基本Feature:负载均衡算法健康检查会话保持...原创 2019-04-19 15:50:04 · 1623 阅读 · 0 评论 -
springboot 关于 Class path contains multiple SLF4J bindings.警告的解决
问题springboot 关于 Class path contains multiple SLF4J bindings.警告的解决 有一次配置好springboot项目启动后,忽然发现有下边的警告:SLF4J: Class path contains multiple SLF4J bindings.SLF4J: Found binding in [jar:file:/E:/mavenJa...原创 2019-04-24 15:32:15 · 1732 阅读 · 1 评论 -
164. Maximum Gap
Maximum GapGiven an unsorted array, find the maximum difference between the successive elements in its sorted form.Return 0 if the array contains less than 2 elements.Example 1:Input: [3,6,9,1]...原创 2019-04-24 16:22:20 · 125 阅读 · 0 评论 -
318. Maximum Product of Word Lengths
Maximum Product of Word LengthsGiven a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word...原创 2019-05-01 11:29:39 · 121 阅读 · 0 评论 -
134. Gas Station
Gas StationMediumThere 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 fr...原创 2019-05-06 15:28:36 · 119 阅读 · 0 评论 -
210. Course Schedule II
QuestionThere are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed a...原创 2019-05-06 15:40:35 · 89 阅读 · 0 评论 -
Spring笔记
1、springboot获取当前项目路径的地址 System.getProperty("user.dir")2、springboot获取项目根目录classpath//获取根目录File path = new File(ResourceUtils.getURL("classpath:").getPath());if(!path.exists()) path = new File(...原创 2019-05-29 15:35:09 · 95 阅读 · 0 评论 -
GeoJsonPoints的问题
项目里存储车辆位置用到了mongdb的GeoJsonPoints,但是报错说反序列化找不到默认的构造器(no args construtor like new GeoJsonpoints(){}…)查找了相似的问题和帖子:https://stackoverflow.com/questions/52915203/jackson-serialize-geojsonpoint-as-latitud...原创 2019-06-02 14:33:53 · 2013 阅读 · 1 评论 -
Kafka学习
kafka简介Kafka 是LinkedIn 开发的一个高性能、分布式的消息系统,广泛用于日志收集、流式数据处理、在线和离线消息分发等场景。虽然不是作为传统的MQ来设计,在大部分情况,Kafaka 也可以代替原先ActiveMQ 等传统的消息系统。Kafka 将消息流按Topic 组织,保存消息的服务器称为Broker,消费者可以订阅一个或者多个Topic。为了均衡负载,一个Topic 的...原创 2019-06-02 19:18:17 · 192 阅读 · 0 评论 -
mysql 解析表格的json类型数据
问题解析Mysql表的json字段解决办法JSON_EXTRAC表里table有一个extra字段,字段是text类型,数据为json格式 {"value":"abc"}通过jSON_EXTRACT可以获取json里面value对于的值JSON_EXTRACT(table.extra,'$.value')得到 "abc"如果想去除两侧引号,需要先做类型转换再做trim...原创 2019-06-24 11:41:59 · 1102 阅读 · 0 评论 -
pydicom笔记
处理医疗影像的Python利器:PyDicomhttps://zhuanlan.zhihu.com/p/59413289dicom文件预处理https://blog.csdn.net/qq_35358021/article/details/82857439原创 2019-06-28 19:45:18 · 6956 阅读 · 0 评论 -
Gatling 测试脚本编写及 API 介绍
Gatling基于Scala开发的压测工具,我们可以通过录制自动生成脚本,也可以自己编写脚本,大家不用担心,首先脚本很简单常用的没几个,另外gatling封装的也很好我们不需要去专门学习Scala语法,当然如果会的话会更好。脚本示例import io.gatling.core.Predef._import io.gatling.http.Predef._import scala.co...原创 2019-06-28 19:47:31 · 1601 阅读 · 0 评论 -
MockMvc - SpringMVC单元测试的独立测试:
★ MockMvc - SpringMVC单元测试的独立测试:一、简介为何使用MockMvc? 对模块进行集成测试时,希望能够通过输入URL对Controller进行测试,如果通过启动服务器,建立http client进行测试,这样会使得测试变得很麻烦,比如,启动速度慢,测试验证不方便,依赖网络环...原创 2019-07-05 11:47:40 · 326 阅读 · 0 评论 -
mysql分组取每组前几条记录(排名) 附group by与order by的研究
--按某一字段分组取最大(小)值所在行的数据/*数据如下:namevalmemoa2a2(a的第二个值)a1a1--a的第一个值a3a3:a的第三个值b1b1--b的第一个值b3b3:b的第三个值b2b2b2b2b2b4b4b4b5b5b5b5b5b5*/...原创 2019-07-05 11:55:57 · 1699 阅读 · 0 评论 -
mybatis中#{}和${}的区别及order by的sql注入问题
mybatis的#{}和${}的区别以及order by注入问题原文 http://www.cnblogs.com/chyu/p/4389701.html前言略,直奔主题…#{}相当于jdbc中的preparedstatement${}是输出变量的值简单的说就是#{}传过来的参数带单引号’’,而${}传过来的参数不带单引号。你可能说不明所以,不要紧我们看2段代码:String sq...原创 2019-07-19 14:57:25 · 1103 阅读 · 0 评论 -
Json库
一. 简介和优劣1.Google的GsonGson是目前功能最全的Json解析神器,Gson当初是为因应Google公司内部需求而由Google自行研发而来,但自从在2008年五月公开发布第一版后已被许多公司或用户应用。Gson的应用主要为toJson与fromJson两个转换函数,无依赖,不需要例外额外的jar,能够直接跑在JDK上。而在使用这种对象转换之前需先创建好对象的类型以及其成员才...原创 2019-07-19 15:15:48 · 256 阅读 · 0 评论 -
JVM 调优
java 应用1 cpu 负载过高1.1 分析问题 首先我们通过top 命令进行分析,找出消耗最多cpu的java 进程id 。 找出对应的进程id 后,我们可以通过 top -Hp 进程id 命令来找出该进程中占用cpu最多的前几个线程id。 我们使用 jstack -l 进程pid > /tmp/java_pid.log 输出java的堆栈日志到文...原创 2019-05-29 14:52:33 · 256 阅读 · 0 评论 -
外观模式(Facade模式)
在现实生活中,常常存在办事较复杂的例子,如办房产证或注册一家公司,有时要同多个部门联系,这时要是有一个综合部门能解决一切手续问题就好了。软件设计也是这样,当一个系统的功能越来越强,子系统会越来越多,客户对系统的访问也变得越来越复杂。这时如果系统内部发生改变,客户端也要跟着改变,这违背了“开闭原则”,也违背了“迪米特法则”,所以有必要为多个子系统提供一个统一的接口,从而降低系统的耦合度,这就是外观...原创 2019-05-28 23:25:34 · 550 阅读 · 0 评论 -
636. Exclusive Time of Functions
题目 计算函数执行时长。On a single threaded CPU, we execute some functions. Each function has a unique id between 0 and N-1.We store logs in timestamp order that describe when a function is entered or exit...原创 2019-05-01 13:35:33 · 180 阅读 · 0 评论 -
191. Number of 1 Bits
问题Write a function that takes an unsigned integer and return the number of ‘1’ bits it has (also known as the Hamming weight).Example 1:Input: 00000000000000000000000000001011Output: 3Explanation...原创 2019-05-06 16:59:15 · 166 阅读 · 0 评论 -
212. Word Search II
问题Given a 2D board and a list of words from the dictionary, find all words in the board.Each word must be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those hor...原创 2019-05-06 17:10:39 · 141 阅读 · 0 评论