
Java
徐不依
这个作者很懒,什么都没留下…
展开
-
Java的四种访问修饰符
成员变量有四种修饰符 :private 私有的 package/friendly/default 不写 protected 受保护的 public 公共的类和类之间的关系有如下几种:以Hero为例自身:指的是Hero自己同包子类:ADHero这个类是Hero的子类,并且和Hero处于同一个包下不同包子类:Support这个类是Hero的子类,但是在另一个原创 2017-06-14 11:09:51 · 828 阅读 · 0 评论 -
剑指_栈的压入弹出序列
题目描述输入两个整数序列,第一个序列表示栈的压入顺序,请判断第二个序列是否可能为该栈的弹出顺序。假设压入栈的所有数字均不相等。例如序列1,2,3,4,5是某栈的压入顺序,序列4,5,3,2,1是该压栈序列对应的一个弹出序列,但4,3,5,1,2就不可能是该压栈序列的弹出序列。(注意:这两个序列的长度是相等的)分析首先定义一个栈,从压栈序列和弹出序列首元素往后遍历,如果栈是空的就把压栈序...原创 2019-02-24 21:32:37 · 107 阅读 · 0 评论 -
剑指_顺时针打印矩阵
题目描述输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下4 X 4矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10.分析好像以前在leetcode上做过这道题,思路很明确就是一圈一圈的递归,需要设置四个变量标志上下左右的边界,...原创 2019-02-23 23:26:55 · 158 阅读 · 0 评论 -
Java多线程面试高频问题
1. 简述线程,程序、进程的基本概念。以及他们之间关系是什么?线程与进程相似,但线程是一个比进程更小的执行单位。一个进程在其执行的过程中可以产生多个线程。与进程不同的是同类的多个线程共享同一块内存空间和一组系统资源,所以系统在产生一个线程,或是在各个线程之间作切换工作时,负担要比进程小得多,也正因为如此,线程也被称为轻量级进程。程序是含有指令和数据的文件,被存储在磁盘或其他的数据存储设备中...转载 2019-02-21 15:25:40 · 256 阅读 · 0 评论 -
Java基础之—反射的使用方法,优缺点,应用场景
原文 :https://blog.youkuaiyun.com/sinat_38259539/article/details/71799078https://segmentfault.com/a/1190000010162647?utm_source=tuicool&utm_medium=referral反射是框架设计的灵魂(使用的前提条件:必须先得到代表的字节码的Class,Class类用...转载 2019-02-21 14:35:02 · 877 阅读 · 0 评论 -
20. Valid Parentheses && 32. Longest Valid Parentheses (String, Stack, DP)
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of b...原创 2019-01-23 11:05:17 · 311 阅读 · 0 评论 -
23. Merge k Sorted Lists (Divide and conquer, Linked List) 以及java匿名内部类
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:Input:[ 1->4->5, 1->3->4, 2->6]Output: 1->1->2->3->4-...原创 2019-01-16 17:05:40 · 238 阅读 · 0 评论 -
120. Triangle (DP)
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4], [6,5...原创 2019-01-15 22:38:36 · 141 阅读 · 0 评论 -
IDEA2018激活~亲测可用
https://blog.youkuaiyun.com/halen001/article/details/81137092配置:https://blog.youkuaiyun.com/qq_38775862/article/details/82048119主题下载:http://www.riaway.com/原创 2019-01-15 10:40:25 · 839 阅读 · 0 评论 -
剑指_滑动窗口的最大值
给定一个数组和滑动窗口的大小,找出所有滑动窗口里数值的最大值。例如,如果输入数组{2,3,4,2,6,2,5,1}及滑动窗口的大小3,那么一共存在6个滑动窗口,他们的最大值分别为{4,4,6,6,6,5}; 针对数组{2,3,4,2,6,2,5,1}的滑动窗口有以下6个: {[2,3,4],2,6,2,5,1}, {2,[3,4,2],6,2,5,1}, {2,3,[4,2,6],2,5,1}, ...原创 2019-02-19 15:28:45 · 125 阅读 · 0 评论 -
剑指_用两个栈实现队列
题目描述用两个栈来实现一个队列,完成队列的Push和Pop操作。 队列中的元素为int类型。一个栈(如stack1)只能用来存,另一个栈(如stack2)只能用来取 每次必须有一个栈为空,即所有元素必须同时在一个栈中 当加入元素时首先检查stack2是否为空,如果不空将stack1中的元素全部倒入stack2,否则直接加入到栈1。加入之后再倒回是stack2 import ...原创 2019-02-19 15:59:36 · 128 阅读 · 0 评论 -
LeetCode数组类知识点&题型总结
参考博主charlotte的总结,记录自己的刷题过程。她真的很棒~https://github.com/huxiaoman7/leetcodebookhttps://mp.weixin.qq.com/s?__biz=MzI0OTQwMTA5Ng==&mid=2247483819&idx=1&sn=071731261441f702f429ae9fc1b98b84&...原创 2019-05-23 14:19:55 · 2388 阅读 · 0 评论 -
130. Surrounded Regions (DFS)
经过一个月的倦怠期,我徐汉三又回来啦!FLAG每天至少一道题坚持到秋招offer!!!今天的题目是DFS思想。https://leetcode.com/problems/surrounded-regions/Given a 2D board containing'X'and'O'(the letter O), capture all regions surrounded by'X...原创 2019-04-16 22:33:36 · 202 阅读 · 0 评论 -
星环后台研发实习面经
约了下午两点的面试,两点零几分电话打过来了,还是很准时的。面试官的声音听起来很年轻随和,但是我还是很紧张。。毕竟是第一次技术面试的小菜鸡~总共面了40多分钟。下面开始记录问题;1. 自我介绍一下2. 看你在..实习过,介绍一下你在那里的工作3. 因为涉及到Hadoop,那你对Zookeeper了解吗?他是做什么的?Apache ZooKeeper是由集群(节点组)使用的一种服务...原创 2019-03-10 15:43:07 · 1443 阅读 · 1 评论 -
Java面试题目整理
1. Arrays.sort(), Collections.sort()的底层实现jdk1.7之前是归并,之后改成了TimSortCollections.sort()调用的Arrays.sort() 数组大小小于MIN_MERGE(32)时,用mini-TimSort方法(寻找最长递减子序列然后反转)。长度比较大时,先扫描一次array,找到已经排好的序列,然后再用刚才的mini-Ti...原创 2019-03-14 23:41:49 · 149 阅读 · 0 评论 -
大数相乘不能用自带大数类型
大数乘法基本思想:输入字符串,转成char数组,转成int数组。采用分治思想,每一位的相乘;* 公式:AB*CD = AC (BC+AD) BD* 然后从后到前满十进位,顺序如右(BD,(BC+AD),AC)。公式表示的是什么意思呢?大家回想一下以前小学学的乘法代码如下:package demo.test;import java.util.Scanner;...转载 2019-03-10 15:42:47 · 178 阅读 · 0 评论 -
剑指_复杂链表的复制
题目描述输入一个复杂链表(每个节点中有节点值,以及两个指针,一个指向下一个节点,另一个特殊指针指向任意一个节点),返回结果为复制后复杂链表的head。(注意,输出结果中请不要返回参数中的节点引用,否则判题程序会直接返回空)分析:方法一 用HashMap保存random对应关系,第一遍复制链表,第二遍使用HashMap设置新链表的random对应关系。import java.uti...原创 2019-02-26 11:01:44 · 156 阅读 · 0 评论 -
二叉树的遍历
1. 层次遍历从上往下打印出二叉树的每个节点,同层节点从左至右打印。用一个队列保存还未遍历的节点,每次到一个节点时在队尾加入左右节点。LinkedList实现了Deque和Queue接口。可以分别实现队列栈和双端队列继承Queue的方法:尾部添加(add, offer),查看头部元素(element,peek),删除头部元素(remove,poll) 继承Deque的方法: 对...原创 2019-02-25 10:03:21 · 190 阅读 · 0 评论 -
剑指_二维数组中的查找
题目描述在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。用暴力搜索全部遍历一遍需要O(m*n).但是这样很容易超时。想到对于有一定规律的序列可以用二分法每次排除一些元素进行查找。但是这个二维数组不能直接使用二分法。可以每次将元素和每行最后一个元素比...原创 2019-02-19 16:29:17 · 113 阅读 · 0 评论 -
93. Restore IP Addresses (DFS, String)
Given a string containing only digits, restore it by returning all possible valid IP address combinations.Example:Input: "25525511135"Output: ["255.255.11.135", "255.255.111.35"]思路:合法性的规则:...原创 2019-01-08 15:11:01 · 135 阅读 · 0 评论 -
343. Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.Example 1:Input: 2Output: 1...原创 2019-01-13 21:12:21 · 118 阅读 · 0 评论 -
63. Unique Paths II (Array, DP)
##### 题目描述:A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to...原创 2019-01-03 21:52:27 · 110 阅读 · 0 评论 -
122. Best Time to Buy and Sell Stock II (Array)
##### 题目描述: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 ...原创 2019-01-03 20:36:47 · 121 阅读 · 0 评论 -
167. 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-11-24 22:36:48 · 133 阅读 · 0 评论 -
633. Sum of Square Numbers
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:Input: 5Output: TrueExplanation: 1 * 1 + 2 * 2 = 5 Example 2:...原创 2018-11-24 22:32:10 · 197 阅读 · 0 评论 -
739. Daily Temperatures
Given a list of daily temperatures T, return a list such that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for wh...原创 2018-11-24 16:42:53 · 157 阅读 · 0 评论 -
剑指offer--字符串替换空格
将一个字符串中的空格替换成 "%20"。Input:"We Are Happy"Output:"We%20Are%20Happy"这道题第一眼看好简单啊,直接遍历然后替换空格就好了啊, 唯一要注意是参数StringBuffer形式public class Solution { public String replaceSpace(StringBuffer str)...原创 2018-11-22 10:56:34 · 218 阅读 · 0 评论 -
java导出命令行可执行文件出现报错Error parsing SQL Mapper Configuration. Error parsing Mapper XML. Error resolving
好不容易完成了项目的大部分工作,到了激动人心的部署时刻了。然而,得知之前都是在STS的编译器环境执行的,但是服务器需要在命令行环境可执行的,所以就要导出jar包。好吧==是我无知了。。然后就愉快的开始:在出现的界面中:选择Java-runnable jar file然后next然后重点来了!!!这里一定要选第一个!!!!!把以来的包导到jar里面 否则会无情原创 2017-11-20 21:30:27 · 1501 阅读 · 0 评论 -
java中length,length(),size()区别
1 java中的length属性是针对数组说的,比如说你声明了一个数组,想知道这个数组的长度则用到了length这个属性.2 java中的length()方法是针对字符串String说的,如果想看这个字符串的长度则用到length()这个方法.3.java中的size()方法是针对泛型集合说的,如果想看这个泛型有多少个元素,就调用此方法来查看!这个例子来演示这两个方法和一个属性的用法转载 2017-09-09 20:48:37 · 189 阅读 · 0 评论 -
19. Remove Nth Node From End of List (双指针)
Given a linked list, remove the n-th node from the end of list and return its head.Example:Given linked list: 1->2->3->4->5, and n = 2.After removing the second node from the end, t...原创 2019-01-10 15:56:29 · 720 阅读 · 0 评论 -
78. Subset && 90.Subset 2 (Array, DFS)
##### 78. 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: num...原创 2019-01-06 00:35:26 · 236 阅读 · 0 评论 -
17. Letter Combinations of a Phone Number (DFS, String)
17. Letter Combinations of a Phone NumberGiven a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters ...原创 2019-01-08 10:25:31 · 159 阅读 · 0 评论 -
72. Edit Distance (DP)
Given two words word1 and word2, find the minimum number of operations required to convert word1 to word2.You have the following 3 operations permitted on a word:Insert a character Delete a chara...原创 2019-01-13 12:50:26 · 286 阅读 · 0 评论 -
22. Generate Parentheses (DFS, String)
22. Generate ParenthesesGiven n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:[ "((()))", "(()()...原创 2019-01-07 23:06:24 · 143 阅读 · 0 评论 -
39. Combination Sum 40 Combination Sum 2(Array, DFS)
39. Combination SumGiven 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 tar...原创 2019-01-07 21:56:02 · 164 阅读 · 0 评论 -
96. Unique Binary Search Trees && 95. Unique Binary Search Trees II(DP)
96. Unique Binary Search TreesGiven n, how many structurally unique BST's (binary search trees) that store values 1 ... n?Example:Input: 3Output: 5Explanation:Given n = 3, there are a total ...原创 2019-01-12 21:15:35 · 1398 阅读 · 0 评论 -
139. Word Break (DP)
Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.Note:The ...原创 2019-01-12 19:34:22 · 176 阅读 · 0 评论 -
49. Group Anagrams (String, Map)
Given an array of strings, group anagrams together.Example:Input: ["eat", "tea", "tan", "ate", "nat", "bat"],Output:[ ["ate","eat","tea"], ["nat"原创 2019-01-12 15:30:16 · 167 阅读 · 0 评论 -
46 Permutations && 47 Permutation II (Array, DFS)
78 Permutation IGiven a collection of numbers, return all possible permutations.For example, [1,2,3] have the following permutations: [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], and [3,2,1].和上次...原创 2019-01-06 22:37:00 · 163 阅读 · 0 评论 -
279. Perfect Squares (DFS, DP)
https://leetcode.com/problems/perfect-squares/Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.Example 1:Input: n = 12...原创 2019-06-25 22:38:22 · 207 阅读 · 0 评论