11 2017 档案
摘要:Given a list of strings words representing an English Dictionary, find the longest word in words that can be built one character at a time by other wo
阅读全文
摘要:Given n points in the plane that are all pairwise distinct, a "boomerang" is a tuple of points (i, j, k) such that the distance between iand j equals
阅读全文
摘要:Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrenc
阅读全文
摘要:输入一个递增排序数组的一个旋转,输出旋转数组的最小元素例如1,2,3,4,5的一个旋转可以为3,4,5,1,2把一个数组的最开始若干个元素搬到数组的末尾,称之为数组的旋转 输出旋转数组的最小元素 C++: java:
阅读全文
摘要:Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. Example: Note: 区间求和 C++(166ms): Java(150ms):
阅读全文
摘要: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 cl
阅读全文
摘要:用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。 C++: Java:
阅读全文
摘要:第2章 线程安全性 正确性: 某个类的行为与其规范完全一致。 2.1线程安全: 当多个线程访问某个类时,不管运行时环境采用何种调度方式或者这些线程将如何交替执行,并且在主调代码中不需要任何额外的同步或协同,这个类就能表现出正确的行为,那么就称这个类是线程安全的。 无状态对象: 既不包含任何域,也不包
阅读全文
摘要:Invert a binary tree. to C++(3ms):
阅读全文
摘要:含有abstract修饰符的class即为抽象类,abstract 类不能创建的实例对象。含有abstract方法的类必须定义为abstract class,abstract class类中的方法不必是抽象的。abstract class类中定义抽象方法必须在具体(Concrete)子类中实现,所以
阅读全文
摘要:override(重写,覆盖) 1、方法名、参数、返回值相同。 2、子类方法不能缩小父类方法的访问权限。 3、子类方法不能抛出比父类方法更多的异常(但子类方法可以不抛出异常)。 4、存在于父类和子类之间。 5、方法被定义为final不能被重写。 overload(重载,过载) 1、参数类型、个数、顺
阅读全文
摘要:三大特征是:封装、继承和多态。 封装是指将某事物的属性和行为包装到对象中,这个对象只对外公布需要公开的属性和行为,而这个公布也是可以有选择性的公布给其它对象。在java中能使用private、protected、public三种修饰符或不用(即默认defalut)对外部对象访问该对象的属性和行为进行
阅读全文
摘要:Java平台提供了两种类型的字符串:String和StringBuffer/StringBuilder,它们可以储存和操作字符串。 其中String是只读字符串,也就意味着String引用的字符串内容是不能被改变的。而StringBuffer/StringBuilder类表示的字符串对象可以直接进行
阅读全文
摘要:1、hashCode的存在主要是用于查找的快捷性,如Hashtable,HashMap等,hashCode是用来在散列存储结构中确定对象的存储地址的; 2、如果两个对象相同,就是适用于equals(java.lang.Object) 方法,那么这两个对象的hashCode一定要相同; 3、如果对象的
阅读全文
摘要:Object是所有类的父类,任何类都默认继承Object。 clone 保护方法,实现对象的浅复制,只有实现了Cloneable接口才可以调用该方法,否则抛出CloneNotSupportedException异常 equals 在Object中与==是一样的,子类一般需要重写该方法 hashCod
阅读全文
摘要:首先明确一点,equals是方法,==是操作符。 1. 如果比较的是基本数据类型: 只讨论==,因为equals是不存在的,因为java中基本数据类型不能调用method的。 2. 如果比较的是引用类型: ==:比较两个引用是不是指向同一个对象实例,即相同的地址。 equals:equals方法是O
阅读全文
摘要:Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are n
阅读全文
摘要:Collection 对象的集合 ├ List 子接口 按进入先后有序保存 可重复 │├ LinkedList 接口实现类 链表 插入删除 没有同步 线程不安全 │├ ArrayList 接口实现类 数组 随机访问 没有同步 线程不安全 │└ Vector 接口实现类 数组 同步 线程安全 │ └
阅读全文
摘要:在Java5以前,switch(expr)中,exper只能是byte,short,char,int类型(或其包装类)的常量表达式。 从Java5开始,java中引入了枚举类型,即enum类型。 从Java7开始,exper还可以是String类型。 但是long在所有版本中都是不可以的。 jdk1
阅读全文
摘要:八种基本数据类型的大小,以及他们的封装类 Switch能否用string做参数 equals与==的区别 Object有哪些公用方法 String、StringBuffer与StringBuilder的区别 Java面向对象的三个特征与含义 Override和Overload的区别 Interfac
阅读全文
摘要:基本类型 大小(字节) 默认值 封装类 byte 1 (byte)0 Byte short 2 (short)0 Short int 4 0 Integer long 8 0L Long float 4 0.0f Float double 8 0.0d Double boolean - false
阅读全文
摘要:Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note:n is positive and will fit within the range of a 32-bi
阅读全文
摘要:You have a total of n coins that you want to form in a staircase shape, where every k-th row must have exactly k coins. Given n, find the total number
阅读全文
摘要:什么是Java内存模型: Java虚拟机规范中试图定义一种Java内存模型(Java Memory Model,JMM)来屏蔽掉各种硬件和操作系统的访问差异,以实现让Java程序在各种平台下都能达到一致的内存访问效果。在此之前,主流程序语言(如C/C++等)直接使用物理硬件和操作系统的内存模型,因此
阅读全文
摘要:A self-dividing number is a number that is divisible by every digit it contains. For example, 128 is a self-dividing number because 128 % 1 == 0, 128
阅读全文
摘要:概述: 部分商用虚拟机中,Java程序最初是通过解释器对.class文件进行解释执行的,当虚拟机发现某个方法或代码块运行地特别频繁的时候,就会把这些代码认定为热点代码Hot Spot Code(这也是我们使用的虚拟机HotSpot名称的由来)。为了提高热点代码的执行效率,在运行时,虚拟机将会把这些代
阅读全文
摘要:前言 定位系统问题的时候,知识、经验是基础,数据是依据,工具是运用知识处理数据的手段。这里说的数据包括:运行日志、异常堆栈、GC日志、线程快照、堆转储快照等。经常使用适当的虚拟机监控和分析的工具可以加快分析数据、定位解决问题的速度。 常用命令: 这里主要介绍如下几个工具: 1、jps:查看本机jav
阅读全文
摘要:We define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself. Now, given an integer n, write
阅读全文
摘要:Given a positive integer num, write a function which returns True if num is a perfect square else False. Note: Do not use any built-in library functio
阅读全文
摘要:静态类型,即是变量声明时的类型 实际类型,变量实例化时采用的类型 静态分派 输出: hello,guy! hello,guy! Human man=new Man(); 我们把“Human”称为变量的静态类型,后面的“Man”称为变量的实际类型 编译器在编译期并不知道一个对象的实际类型是什么 编译器
阅读全文
摘要:对象创建方法: JVM遇到一条new指令时,首先检查这个指令的参数是否能在常量池中定位到一个类的符号引用,并且检查这个符号引用代表的类是否已被加载、连接和初始化过。 如果没有,那必须先执行相应的类的加载过程。 对象的内存分配: 对象所需内存的大小在类加载完成后便完全确定(对象内存布局),为对象分配空
阅读全文
摘要:Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For exa
阅读全文
摘要:Given a non-negative integer c, your task is to decide whether there're two integers a and b such that a2 + b2 = c. Example 1: Example 2: java(14ms):
阅读全文
摘要:一个功能健全的Web服务器,要解决如下几个问题: 部署在同一个服务器上的两个Web应用程序使用的Java 类库可以实现相互隔离。不能要求一个类库在一个服务器中只有一份,服务器应当保证两个应用程序的类库可以互相独立使用。 部署在同一个服务器上的两个Web应用程序所使用的Java类库可以互相共享,如果J
阅读全文
摘要:Java 提供了很多服务提供者接口(Service Provider Interface,SPI),允许第三方为这些接口提供实现。常见的 SPI 有 JDBC、JCE、JNDI、JAXP 和 JBI 等。 这些 SPI 的接口由 Java 核心库来提供,而这些 SPI 的实现代码则是作为 Java
阅读全文
摘要:Java中的所有类,都需要由类加载器装载到JVM中才能运行。类加载器本身也是一个类,而它的工作就是把class文件从硬盘读取到内存中。在写程序的时候,我们几乎不需要关心类的加载,因为这些都是隐式装载的,除非我们有特殊的用法,像是反射,就需要显式的加载所需要的类。 类装载方式,有两种 : 1.隐式装载
阅读全文
摘要:Determine whether an integer is a palindrome. Do this without extra space. 判断一个数是不是回文数 C++(182ms): Java(188ms):
阅读全文
摘要:Given two non-negative integers num1 and num2 represented as string, return the sum of num1 and num2. Note: 字符串表示十进制数,求相加后的结果 C++(19ms): java(25ms):
阅读全文
摘要:请实现一个函数,将一个字符串中的空格替换成“%20”。例如,当字符串为We Are Happy.则经过替换之后的字符串为We%20Are%20Happy。 C++: C++: java: java:
阅读全文
摘要:六个创建型模式 简单工厂模式 工厂方法模式 抽象工厂模式 单例模式 原型模式 建造者模式 七个结构型模式 适配器模式 桥接模式 组合模式 装饰模式 外观模式 享元模式 代理模式 十一个行为型模式 职责链模式 命令模式 解释器模式 迭代器模式 中介者模式 备忘录模式 观察者模式 状态模式 策略模式 模
阅读全文
摘要:概括: (串行)Serial收集器:用于新生代,采用复制算法,单线程收集器,它在垃圾收集时,必须暂停其他所有的工作线程。 是虚拟机运行在Client模式下的默认新生代收集器。优点:简单高效。 (并行)ParNew收集器:用于新生代,采用复制算法,Serial的多线程版本,是在Server模式下的虚拟
阅读全文
摘要:Given an m * n matrix M initialized with all 0's and several update operations. Operations are represented by a 2D array, and each operation is repres
阅读全文
摘要:在JDK 1.2以前的版本中,若一个对象不被任何变量引用,那么程序就无法再使用这个对象。也就是说,只有对象处于可触及(reachable)状态,程序才能使用它。从JDK 1.2版本开始,把对象的引用分为4种级别,从而使程序能更加灵活地控制对象的生命周期。这4种级别由高到低依次为:强引用、软引用、弱引
阅读全文
摘要:垃圾回收的意义: Java语言中一个显著的特点就是引入了垃圾回收机制,使c++程序员最头疼的内存管理的问题迎刃而解,它使得Java程序员在编写程序的时候不再需要考虑内存管理。由于有个垃圾回收机制,Java中的对象不再有“作用域”的概念,只有对象的引用才有“作用域”。垃圾回收可以有效的防止内存泄漏,有
阅读全文
摘要:The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of the numbers in the set got duplicated to another n
阅读全文
摘要:撤销永久代,引入元空间: 在 JDK 1.8 中,HotSpot 已经没有 “PermGen space”这个空间了,取而代之是一个叫做 Metaspace(元空间) 的东西。 Java7中已经将字符串常量池从永久代移除,在Java 堆(Heap)中开辟了一块区域存放字符串常量池。而在Java8中,
阅读全文
摘要:运行时数据区域: 根据 JVM 规范,JVM 内存共分为虚拟机栈、堆、方法区、程序计数器、本地方法栈五个部分。 程序计数器(线程私有): 是当前线程所执行的字节码的行号指示器,每条线程都要有一个独立的程序计数器,这类内存也称为“线程私有”的内存。 正在执行java方法的话,计数器记录的是虚拟机字节码
阅读全文
摘要:JVM内存区域的划分(内存结构或者内存模型) Java 8中撤销永久代,引入元空间 JVM的分代思想 对象创建方法,对象的内存分配,对象的访问定位 Java中的四种引用 垃圾回收算法 垃圾收集器 JVM调优工具 描述一下JVM加载class文件的原理机制 线程上下文类加载器 Tomcat的类加载机制
阅读全文
摘要:Java虚拟机根据对象存活的周期不同,把堆内存划分为几块,一般分为新生代、老年代和永久代(对HotSpot虚拟机而言),这就是JVM的内存分代策略。 永久代是HotSpot虚拟机特有的概念,它采用永久代的方式来实现方法区,其他的虚拟机实现没有这一概念,而且HotSpot也有取消永久代的趋势,在JDK
阅读全文
摘要:在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。 1 2 8 92 4 9 124 7 10 116 8 11 15 C++: c++: java:
阅读全文
摘要:Given an integer (signed 32 bits), write a function to check whether it is a power of 4. Example:Given num = 16, return true. Given num = 5, return fa
阅读全文
摘要:Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight). For example, the 32-bit
阅读全文
摘要:Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will always have different values. Example 1: Example 2:
阅读全文
摘要:Given an integer, write a function to determine if it is a power of two. Credits:Special thanks to @jianchao.li.fighter for adding this problem and cr
阅读全文
摘要:We define a harmonious array is an array where the difference between its maximum value and its minimum value is exactly 1. Now, given an integer arra
阅读全文
摘要:Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters. This
阅读全文
摘要:Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings. You need to h
阅读全文
摘要:Given two arrays, write a function to compute their intersection. Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2]. Note: Each elemen
阅读全文
摘要:Given two strings s and t, write a function to determine if t is an anagram of s. For example,s = "anagram", t = "nagaram", return true.s = "rat", t =
阅读全文
摘要:Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive intege
阅读全文