![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Java
文章平均质量分 76
XINGKONG_04
这个作者很懒,什么都没留下…
展开
-
java异常
java的异常机制Throwable类Throwable类是Java异常类型的顶层父类,一个对象只有是 Throwable 类的(直接或者间接)实例,他才是一个异常对象,才能被异常处理机制识别。JDK中内建了一些常用的异常类,我们也可以自定义异常。Throwable又派生出Error类和Exception类。错误:Error类以及他的子类的实例,代表了JVM本身的错误。错误不能被程...原创 2018-07-25 16:20:53 · 300 阅读 · 0 评论 -
Leetcode38 Count and Say
原题The count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211 is read off as "one 1" or 11.11 is read off as ...原创 2018-06-03 23:07:33 · 152 阅读 · 0 评论 -
Leetcode119 Pascal's Triangle II
原题目Given a non-negative index k where k ≤ 33, return the kth index row of the Pascal's triangle.Note that the row index starts from 0.In Pascal's triangle, each number is the sum of the two numbers di...原创 2018-05-26 16:48:30 · 198 阅读 · 0 评论 -
Leetcode66 Plus One
原文题目Given a non-empty array of digits representing a non-negative integer, plus one to the integer.The digits are stored such that the most significant digit is at the head of the list, and each eleme...原创 2018-05-18 09:26:39 · 244 阅读 · 0 评论 -
Leetcode35 Search Insert Position
原文题目Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array....原创 2018-05-17 22:59:41 · 162 阅读 · 0 评论 -
Leetcode122 Best Time to Buy and Sell Stock II
原题目Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many transactions as you like (i.e., buy o...原创 2018-05-17 21:01:17 · 167 阅读 · 0 评论 -
leetcode121 Best Time to Buy and Sell Stock
问题描述Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (i.e., buy one and sell one share of the stock...原创 2018-05-11 10:05:21 · 135 阅读 · 0 评论 -
Leetcode70 Climbing Stairs
问题描述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 climb to the top?Note: Given n will be a positive...原创 2018-05-10 19:17:58 · 144 阅读 · 0 评论 -
Leetcode172 Factorial Trailing Zeroes
题目Given an integer n, return the number of trailing zeroes in n!.Note: Your solution should be in logarithmic time complexity.中文大意给定整数n,返回改整数阶乘n!结果的尾随零的个数分析直观的思路是:先求出阶乘结果n!,然原创 2018-03-05 14:50:28 · 178 阅读 · 0 评论 -
Leetcode398 Random Pick Index
题目Given an array of integers with possible duplicates, randomly output the index of a given target number. You can assume that the given target number must exist in the array.Note:The array size can b...原创 2018-03-05 00:02:48 · 227 阅读 · 0 评论 -
Leetcode130 Surrounded Regions
题目Given a 2D board containing 'X' and 'O' (the letter O), capture all regions surrounded by 'X'.A region is captured by flipping all 'O's into 'X's in that surrounded region.For example,X X X XX O O ...原创 2018-03-03 23:11:33 · 276 阅读 · 0 评论 -
Leetcode628 Maximum Product of Three Numbers
题目Given an integer array, find three numbers whose product is maximum and output the maximum product.Example 1:Input: [1,2,3]Output: 6Example 2:Input: [1,2,3,4]Output: 24Note:The length of the giv...原创 2018-03-02 19:37:27 · 137 阅读 · 0 评论 -
Leetcode 58 Length of Last Word
原题Given a string s consists of upper/lower-case alphabets and empty space characters ' ', return the length of last word in the string.If the last word does not exist, return 0.Note: A word is defined...原创 2018-06-03 23:41:53 · 193 阅读 · 0 评论 -
Leetcode 67
英文原题Given two binary strings, return their sum (also a binary string).The input strings are both non-empty and contains only characters 1 or 0.Example 1:Input: a = "11", b = "1"Output: "100"Example 2...原创 2018-06-11 21:43:41 · 209 阅读 · 0 评论 -
回溯算法原理总结
回溯算法理论总结回溯法是一种类似枚举的搜索尝试过程,既然是枚举,那么就会遍历解空间树中的所有解(或者是“路径”),搜索的过程按照DFS原则,而尝试就意味着,在遍历的过程中,有可能到达某一个结点后,发现不能够满足约束条件,在这次尝试中,这条“路”是不优的,将走不通,即无法找到所求的解,那么就会回退到上一步的状态,重新作出选择。如果即满足约束条件,但是依然没有获得有效的解,那么我们就需要在此基础上...原创 2018-07-19 19:29:09 · 3636 阅读 · 0 评论 -
java内部类
概念内部类:可以包含在另外一个类中的类外部类:包含内部类的类 每个内部类都会被编译为一个独立的类,生成一个独立的字节码文件。内部类可以方便地访问外部类的私有变量,内部类也可以声明为private从而实现对外完全隐藏。 分类java中的四种内部类(根据定义的位置和方式划分)-静态内部类-成员内部类-方法内部类-匿名内部类 分类介绍-静态内部...原创 2018-07-24 15:41:56 · 194 阅读 · 0 评论 -
java中Stack类的介绍
本文主要对java中的Stack源码进行分析。1.Stack类在java.util包中;2.源码顶部注释分析3.继承关系Stack继承了Vector,而Vector类底层使用数组存储数据,那么Stack对象中存储的数据也是存储在数组中的。4.构造函数Stack只有一个无参数的构造函数。5.API介绍(1)push(item):把数据压入栈addElement()是父类Vector中的方法,会将压入...原创 2018-07-06 16:41:25 · 4407 阅读 · 0 评论 -
动态规划算法
动态规划基础理论 动态规划,指通过组合子问题的解来求解原问题。动态规划算法的核心是记住已经解决过的子问题的解。 与分治方法的区别:分治方法将问题划分为互不相交的子问题,递归地求解子问题,再将它们的解组合起来,求出原问题的解。动态规划应用于子问题重叠的情况,即不同的子问题具有公共的子子问题(子问题的求解是递归进行的,将其划分为更小的子子问题)分治算法会做许多不必要的工...原创 2018-07-17 20:28:01 · 433 阅读 · 0 评论 -
java的继承
继承1.java中是单继承的。每个子类只有一个父类。 语法:子类 extends 父类2.在java中,即使没有声明父类,也有一个隐含的父类,就是Object类3.在子类中可以使用super来调用父类的方法 4.继承中的构造方法问题在new一个子类实例的过程中,会优先自动调用父类默认的无参数构造方法,然后再调用子类的构造方法。如果父类没有默认的构造方法,只有带参数的...原创 2018-07-23 14:53:46 · 221 阅读 · 0 评论 -
快速幂算法
原理介绍快速幂的目的就是做到快速求幂,假设我们要求a^b,按照朴素算法就是把a连乘b次,这样一来时间复杂度是O(b)也即是O(n)级别,快速幂能做到O(logn)。我们可以对指数b拆分:(1)如果b为偶数,那么a^b = (a^2)^(b/2);(2)如果b为奇数,那么a^b = a * (a^2)^(b-1)/2);(3)如果b/2为偶数,那么a^b = ((a^2)*(a^2))^(b/4);...原创 2018-07-04 21:10:16 · 452 阅读 · 0 评论 -
java的动态绑定和静态绑定
背景1.当子类和父类存在同一个方法,子类重写了父类的方法,程序在运行时调用的是父类的方法还是子类的重写方法呢(尤其是存在向上类型转换的情况)?2.当一个类中存在方法名相同但参数不同(重载)的方法,程序在执行的时候该如何辨别区分使用哪个方法呢?在java中存在绑定的机制解决以上疑问。 绑定绑定:将一个方法的调用与方法所在的类(方法主体)关联起来。即决定调用哪个方法和变量。...原创 2018-07-23 10:58:10 · 6254 阅读 · 4 评论 -
排序算法汇总
1.冒泡排序参考链接:排序算法总结原创 2018-06-29 10:42:00 · 231 阅读 · 0 评论 -
Leetcode283 Move Zeroes
原题Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.Example:Input: [0,1,0,3,12]Output: [1,3,12,0,0]Note:You must do ...原创 2018-05-29 11:21:43 · 146 阅读 · 0 评论 -
Leetcode167 Two Sum II - Input array is sorted
原题Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers ...原创 2018-05-29 10:13:00 · 133 阅读 · 0 评论 -
Leetcode 168 Excel Sheet Column Title
原题Given a positive integer, return its corresponding column title as appear in an Excel sheet.For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 -> ...原创 2018-06-05 08:58:44 · 136 阅读 · 0 评论 -
Leetcode260 Single Number III
题目Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:原创 2018-03-02 09:24:20 · 167 阅读 · 0 评论 -
Leetcode643 Maximum Average Subarray I
题目Given an array consisting of n integers, find the contiguous subarray of given length k that has the maximum average value. And you need to output the maximum average value.Example 1:原创 2018-02-28 20:14:40 · 222 阅读 · 0 评论 -
Leetcode553 Optimal Division
题目Given a list of positive integers, the adjacent integers will perform the float division. For example, [2,3,4] -> 2 / 3 / 4.However, you can add any number of parenthesis at any position原创 2018-02-28 19:55:37 · 227 阅读 · 0 评论 -
Leetcode003 Longest Substring Without Repeating Characters
问题:Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer原创 2017-12-06 15:01:19 · 156 阅读 · 0 评论 -
Java-Arrays工具类
Arrays类功能描述Arrays类是一个工具类,其中包含了数组操作的很多方法,比如搜索和排序;Arrays类中的方法均为static修饰的,可以直接通过Arrays.xxx(xxx)的形式调用方法。几个重要方法asList(T... a)由给定的数组a,返回一个固定大小的List。在这里,着重解释一下前面这句话的深层含义,我们可以看Arrays类的源码原创 2017-11-26 18:31:34 · 366 阅读 · 0 评论 -
Leetcode020 Valid Parentheses
Leetcode020 Valid Parentheses问题描述Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the co原创 2017-12-12 16:49:43 · 204 阅读 · 0 评论 -
Java的全局变量和局部变量
转载原文地址java中的局部变量和全局变量1、局部变量:局部变量的定义:定义在方法中的变量都是局部变量(main方法也是方法,所以定义在main方法中的变量也是局部变量)。生存时间:局部变量的生存时间和方法的生存时间一致,调用该方法,声明该局部变量并初始化的时候,该局部变量被创建并分配内存空间;直到该方法调用结束,局部变量也就结束了;是否需要初始化:局部变量在使转载 2017-11-23 15:10:19 · 687 阅读 · 0 评论 -
Java的基本数据类型
Java的8种基本数据类型8种基本数据类型 名称 表示 位数 范围 示例 封装类 默认值 备注 字节型 byte 8 -2^7~2^7-1 127 Byte 0 短整型 short 16 -2^15~2^15-1 32767 Short 0 整型 int 32 -2^31~2^31-1原创 2017-11-23 14:22:07 · 230 阅读 · 0 评论 -
Leetcode 008 String to Integer
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca原创 2017-11-23 14:25:31 · 229 阅读 · 0 评论 -
Java基础之final
final修饰符final可以修饰类、方法、属性(变量)final修饰类当一个类被final所修饰时,表示该类是一个终态类,不能被继承(即不能再拥有子类)final修饰方法当一个方法被final所修饰时,表示该方法不能被重写final修饰属性当一个属性被final所修饰时 ,表示该属性不能被改写。所以当final修饰属性时,一定要赋予初始值,因为以后将没有机会再赋值原创 2017-12-11 15:55:37 · 196 阅读 · 0 评论 -
Java基础之static
static修饰符修饰范围:方法、属性(变量)、类、代码块static修饰方法static修饰的方法叫做静态方法。可以使用类名.方法名的方式调用方法(Java推荐使用),也可以实例化类后再调用(会有警告)。static方法在继承中的影响:静态方法,只能继承,不能重写1.对于父类、子类中的方法均未被static修饰,那么在子类中是可以重写父类中的方法的(类似于普通的情原创 2017-12-11 15:32:25 · 191 阅读 · 0 评论 -
JAVA环境配置
转载原地址:http://www.cnblogs.com/Belieflee/p/4778315.html一、安装JDK1、 JVM(Java Virtual Machine—Java虚拟机)JRE(Java Runtime Environment—Java运行时环境)JDK(Java Development kit—Java开发工具包)2、JDK包含了JR转载 2017-09-19 10:06:30 · 409 阅读 · 0 评论 -
Object方法学习之equals
在实际的开发中,我们经常使用equals()方法来做判断,所以今天就介绍一下equals()方法。 equals()方法,该方法定义在Object类当中,因此Java中的每个类都具有该方法,对于Object类的equals()方法来说,它是判断调用equals()方法的引用与传进来的引用是否一致,即这两个引用是否指向同一个对象。对于Object类的equals()方法来说,相当于“==”原创 2017-08-23 08:59:55 · 271 阅读 · 0 评论 -
Object类中方法总结之toString()
可还记得java入门的第一课么??System.out.println("hello world")。显而易见这个结果是一个字符串喽,可是如果括号中的参数是一个应用实例呢?那么会怎样呢?接下来就得来学习一下toString()方法究竟都干了些啥…… toString():该方法返回一个表示该对象的字符串,返回值内容包括:实例对应类名+@+对象哈希值的十六进制表示值,实现过称为: getClass(原创 2017-08-22 10:58:47 · 1223 阅读 · 0 评论 -
Leetcode007 Reverse Integer
题目要求:Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21原创 2017-12-06 15:37:24 · 178 阅读 · 0 评论