自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(82)
  • 收藏
  • 关注

原创 两个非负字符串相加

class Solution {public:    string addStrings(string num1, string num2) {        int size1 = num1.size();        int size2 = num2.size();        int size3 = max(size1,size2)+1;        vector<int>...

2018-05-30 23:45:20 279

原创 两个非负数相乘

Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string.Example 1:Input: num1 = "2", num2 = "3"Output: "6"Example 2:Inp...

2018-05-30 23:15:33 400

原创 kmp 字符串匹配

 Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: haystack = "hello", needle = "ll"Output: 2Exam...

2018-05-30 10:35:48 119

转载 AQS

一、概述  谈到并发,不得不谈ReentrantLock;而谈到ReentrantLock,不得不谈AbstractQueuedSynchronized(AQS)!  类如其名,抽象的队列式的同步器,AQS定义了一套多线程访问共享资源的同步器框架,许多同步类实现都依赖于它,如常用的ReentrantLock/Semaphore/CountDownLatch...。  以下是本文的目录大纲:概述框架...

2018-05-29 17:19:04 694

转载 ReentrantLock 的使用

作者:骊骅链接:https://www.jianshu.com/p/155260c8af6c來源:简书著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。一、初识ReentrantLockimport java.util.concurrent.locks.ReentrantLock;/** * Created by haicheng.lhc on 17/05/...

2018-05-29 15:43:17 5978 3

转载 java可重入锁(ReentrantLock)的实现原理

前言相信学过java的人都知道 synchronized 这个关键词,也知道它用于控制多线程对并发资源的安全访问,兴许,你还用过Lock相关的功能,但你可能从来没有想过java中的锁底层的机制是怎么实现的。如果真是这样,而且你有兴趣了解,今天我将带领你轻松的学习下java中非常重要,也非常基础的可重入锁-ReentrantLock的实现机制。听故事把知识掌握了在一个村子里面,有一口井水,水质非常的...

2018-05-29 15:06:38 668

转载 JDK 5.0 中更灵活、更具可伸缩性的锁定机制ReentrantLock

多线程和并发性并不是什么新内容,但是 Java 语言设计中的创新之一就是,它是第一个直接把跨平台线程模型和正规的内存模型集成到语言中的主流语言。核心类库包含一个 Thread 类,可以用它来构建、启动和操纵线程,Java 语言包括了跨线程传达并发性约束的构造 —— synchronized 和 volatile 。在简化与平台无关的并发类的开发的同时,它决没有使并发类的编写工作变得更繁琐,只是使它...

2018-05-29 14:53:29 127

转载 Java中volatile关键字实现原理

作者:知乎用户链接:https://www.zhihu.com/question/49656589/answer/117826278来源:知乎著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。volatile 只能保证 “可见性”,不能保证 “原子性”。count++; 这条语句由3条指令组成:(1)将 count 的值从内存加载到 cpu 的某个寄存器r(...

2018-05-29 14:13:25 1714

原创 java 中的匿名类

匿名内部类也就是没有名字的内部类正因为没有名字,所以匿名内部类只能使用一次,它通常用来简化代码编写但使用匿名内部类还有个前提条件:必须继承一个父类或实现一个接口 实例1:不使用匿名内部类来实现抽象方法12345678910111213141516abstract class Person {    public abstract void eat();} class Child extends P...

2018-05-29 11:11:15 99

转载 乱序中找出第一次未出现的正整数

Given an unsorted integer array, find the first missing positive integer.For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2.Your algorithm should run in O(n) time and uses constant space...

2018-05-29 01:03:38 479

原创 格雷码生成

格雷码的规律,比如n=3时000001011010110111101100规律是 将格雷码看成是上下两部分 n=1 上 0  下 1n=2上为n=1时的格雷码 下为n=1时的格雷码的倒序再加上最前面的1class Solution {public:        // 除去最高位 对称    vector<int> grayCode(int n) {                ve...

2018-05-29 00:34:31 953

原创 拦截器的使用

1,拦截器的概念    java里的拦截器是动态拦截Action调用的对象,它提供了一种机制可以使开发者在一个Action执行的前后执行一段代码,也可以在一个Action执行前阻止其执行,同时也提供了一种可以提取Action中可重用部分代码的方式。在AOP中,拦截器用于在某个方法或者字段被访问之前,进行拦截然后再之前或者之后加入某些操作。目前,我们需要掌握的主要是Spring的拦截器,Struts...

2018-05-28 16:55:00 220 1

转载 springmvc 中的拦截器

简介SpringWebMVC的处理器拦截器,类似于Servlet开发中的过滤器Filter,用于处理器进行预处理和后处理。应用场景1、日志记录,可以记录请求信息的日志,以便进行信息监控、信息统计等。2、权限检查:如登陆检测,进入处理器检测是否登陆,如果没有直接返回到登陆页面。3、性能监控:典型的是慢日志。HandlerInterceptorpublic interface HandlerInter...

2018-05-28 16:31:07 89

原创 System类

System类代表系统,系统级的很多属性和控制方法都放置在该类的内部。该类位于java.lang包。currentTimeMillis方法public static long currentTimeMillis()该方法的作用是返回当前的计算机时间,时间的表达格式为当前计算机时间和GMT时间(格林威治时间)1970年1月1号0时0分0秒所差的毫秒数。可以直接把这个方法强制转换成date类型。代码如...

2018-05-28 15:15:10 230

原创 @Controller和@RestController的区别?

@RestController注解相当于@ResponseBody + @Controller合在一起的作用。1.使用@Controller 注解,在对应的方法上,视图解析器可以解析return 的jsp,html页面,并且跳转到相应页面若返回json等内容到页面,则需要加@ResponseBody注解 @CrossOrigin@Controllerpublic class FileUploadC...

2018-05-28 14:59:49 127

转载 Java新手如何学习Spring、Stuts、springmvcHibernate三大框架?

基本概念:Spring/Struts/Hibernate是干嘛用的?三个框架产生的技术历史背景学习前首先应该掌握的基础知识学习一个开发框架的基本方法如何学习Spring框架如何学习ORM框架如何学习MVC框架第一部分:基本概念首先我们应该了解这三个框架分别是做什么的,在Java开发中具有什么样的作用,对于理清楚框架中具体的知识点是大有裨益的。 1. Spring:DI/AOPSpring对应的关键...

2018-05-28 14:46:57 1033

转载 判断是否为二叉搜索树

 Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key. T...

2018-05-23 23:56:41 155

转载 字符串最小窗口Minimum Window Substring

 Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).Example:Input: S = "ADOBECODEBANC", T = "ABC"Output: "BANC"Note:...

2018-05-22 23:22:18 180

转载 大于s最小的子数字的和 Minimum Size Subarray Sum

 Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn't one, return 0 instead.Example: Input: [2,3...

2018-05-22 22:31:50 141

原创 数组的子集Subsets 不能重复

Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.Example:Input: [1,2,2]Output:...

2018-05-22 19:12:24 201

原创 数组的子集Subsets

Given a set of distinct integers, nums, return all possible subsets (the power set).Note: The solution set must not contain duplicate subsets.Example:Input: nums = [1,2,3]Output:[ [3],  [1],  [2...

2018-05-22 09:21:18 138

原创 数字组合sum 不可以重复并且去重复

Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.Each number in candidates may o...

2018-05-21 23:56:34 1245

原创 数字组合sum 可以重复的

Given a set of candidate numbers (candidates) (without duplicates) and a target number (target), find all unique combinations in candidates where the candidate numbers sums to target.The same repeated...

2018-05-21 23:45:50 241

原创 gcc 与 g++ 区别

一:gcc与g++比较编译c/c++代码的时候,有人用gcc,有人用g++,于是各种说法都来了,譬如c代码用gcc,而 c++代码用g++,或者说编译用gcc,链接用g++,一时也不知哪个说法正确,如果再遇上个extern "C",分歧就更多了,这里我想作个了结,毕竟知识的目的是令人更清醒,而不是更糊涂。误区一:gcc只能编译c代码,g++只能编译c++代码两者都可以,但是请注意:1.后缀为.c的...

2018-05-20 17:39:20 913

原创 mac 下破解SecureCRT和安装步骤

先链接:https://pan.baidu.com/s/1-1nu4eRf7BmuLg5MtlCRvw  密码:30pq    默认下载到了当前用户的”下载”目录中在”Finder”中 打开 “scrt-7.3.0-657.osx_x64.dmg” 并将 SecureCRT复制到”应用程序”中. 这时SecureCRT的路径是: /Applications/SecureCRT.app/Conten...

2018-05-19 08:38:36 8638 4

转载 数组的最大乘积子序列

  Given an integer array nums, find the contiguous subarray within an array (containing at least one number) which has the largest product.Example 1:Input: [2,3,-2,4]Output: 6Explanation: [...

2018-05-19 01:09:46 388

转载 丑数是求取

  Example:Input: n = 10Output: 12Explanation: 1, 2, 3, 4, 5, 6, 8, 9, 10, 12 is the sequence of the first 10 ugly numbers. class Solution {public:    int nthUglyNumber(int n) {       ...

2018-05-17 23:50:06 72

转载 s1和s2 能否构成s3

 Example 1:Input: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbcbcac"Output: trueExample 2:Input: s1 = "aabcc", s2 = "dbbca", s3 = "aadbbbaccc"Output: false class Solution {public: 

2018-05-17 08:49:39 844

转载 单词word1到word2的最小编辑次数

Example 1:Input: word1 = "horse", word2 = "ros"Output: 3Explanation: horse -> rorse (replace 'h' with 'r')rorse -> rose (remove 'r')rose -> ros (remove 'e')Example 2:Input: word...

2018-05-16 23:54:24 939

原创 GC算法和种类

gc的概念Garbage Collection 垃圾收集 后台有一个垃圾回收的线程,不断的扫描1960年    List使用了GCjava中   GC的对象是堆空间和永久区-----------------------------------引用计数的思想---------------------------------标记-清除方法...

2018-05-16 13:11:30 92

转载 Longest Valid Parentheses最长有效括号

Example 1:Input: "(()"Output: 2Explanation: The longest valid parentheses substring is "()"Example 2:Input: ")()())"Output: 4Explanation: The longest valid parentheses substring is "()()"...

2018-05-16 00:14:54 128

原创 java 中this指针

应用一:引用成员变量 如上面这段代码中,有一个成员变量name,同时在方法中有一个形式参数,名字也是name,然后在方法中将形式参数name的值传递给成员变量name,虽然我们可以看明白这个代码的含义,但是作为Java编译器它是怎么判断的呢?到底是将形式参数name的值传递给成员变量name,还是反过来将成员变量name的值传递给形式参数name呢?也就是说,两个变量名字如果相同的话,那么Jav...

2018-05-15 11:03:44 561

原创 常用的jvm配置参数 :永久区参数配置

一开始java程序起来了 PermSize 大小如果不够的话,MaxPermSize 为最大的情况。如果超过了就会oom永久区表达能够容纳多少个类型,一般来讲不大,几十兆到几百兆-----------------------------------------------栈表示线程私有的。每个线程都会有的,不会很大。--------------栈空间的大小的分配溢出...

2018-05-15 00:24:46 553

转载 矩阵的左上角到右下角到路径数量,中间有障碍物

 Input:[  [0,0,0],  [0,1,0],  [0,0,0]]Output: 2Explanation:There is one obstacle in the middle of the 3x3 grid above.There are two ways to reach the bottom-right corner:1. Right -> Rig...

2018-05-14 23:40:35 2034

转载 ava并发编程-无锁CAS与Unsafe类及其并发包Atomic

在前面一篇博文中,我们曾经详谈过有锁并发的典型代表synchronized关键字,通过该关键字可以控制并发执行过程中有且只有一个线程可以访问共享资源,其原理是通过当前线程持有当前对象锁,从而拥有访问权限,而其他没有持有当前对象锁的线程无法拥有访问权限,也就保证了线程安全。但在本篇中,我们将会详聊另外一种反向而行的并发策略,即无锁并发,即不加锁也能保证并发执行的安全性。 本篇的思路是先阐明无锁执行者...

2018-05-14 18:25:27 158

转载 NIO 的例子

NIO是Java提供的非阻塞I/O API。非阻塞的意义在于可以使用一个线程对大量的数据连接进行处理,非常适用于"短数据长连接"的应用场景,例如即时通讯软件。在一个阻塞C/S系统中,服务器要为每一个客户连接开启一个线程阻塞等待客户端发送的消息.若使用非阻塞技术,服务器可以使用一个线程对连接进行轮询,无须阻塞等待.这大大减少了内存资源的浪费,也避免了服务器在客户线程中不断切换带来的CPU消耗,服务器...

2018-05-14 16:14:43 110

转载 为什么要有NIO

我是Java IO, 你可能听说过我,了解过我,用我的API写过简单的程序, 但估计大部分人也就此打住, 对我的了解并不深入。这也难怪,毕竟在实际的工作当中,直接使用我的API来操作文件的机会并不多,  更多时候你只需要把配置文件(xml, properties等)放到指定的位置, 剩下的工作就交给框架去处理了,  框架会把这些配置数据变成Java 对象来让你调用, 不用你去操心IO细节。有些人以...

2018-05-14 16:04:01 875 3

转载 IO 与 NIO 的区别

IO是计算机中Input和Output简称,即输入和输出。 无论是系统、还是语言的设计中IO的设计都是异常复杂的。Java语言在IO设计方面是比较成功的,不仅是面向对象,而且利用装饰器设计模式(后面会写针对设计模式的文章)减少了大量的类,提供了较好的扩展性。那Java IO怎么写入/读取数据?Java IO类库可以分为输入流和输出流,输入流来读数据,输出流来写数据。输出流实例代码一: //输...

2018-05-14 14:35:00 110

转载 矩阵中左上角到右下角到种数

 Example 1:Input: m = 3, n = 2Output: 3Explanation:From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:1. Right -> Right -> Down2. Right -> Down -...

2018-05-13 00:14:18 645

转载 矩阵的最小路径之和dp

 Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right a...

2018-05-12 23:07:08 215

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除