java常见知识
文章平均质量分 54
总结常见java面试题,笔试题
hanruikai
aaa
展开
-
JDK 8 的optional类
什么是Optional类NPE(Null Pointer Exception)一直是我们最头疼的问题,也是最容易忽视的地方。NPE常是导致Java应用程序失败的最常见的原因。在日常研发工作中,经常会处理各种变量、集合,但在使用的过程中,往往要进行空判断,不然会出现NPE。Optional类实际上是个容器:它可以保存类型T的值,或者仅仅保存null。Optional 类的引入很好的解决空指针异常。Optional提供很多有用的方法,这样我们就不用显式进行空值检测。尽量避免在程序中直接调用Optiona原创 2021-02-23 16:56:36 · 8548 阅读 · 6 评论 -
LeetCode刷题Easy篇. Palindrome Linked List
题目Given a singly linked list, determine if it is a palindrome.Example 1:Input: 1->2Output: falseExample 2:Input: 1->2->2->1Output: trueFollow up:Could you do it in O(n) ti...原创 2018-12-13 18:02:38 · 216 阅读 · 0 评论 -
LeetCode刷题EASY篇 Implement Queue using Stacks
题目Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue. pop() -- Removes the element from in front of queue. peek() -- Get the front element....原创 2018-12-13 17:21:20 · 192 阅读 · 0 评论 -
LeetCode刷题EASY篇Power of Two
题目Given an integer, write a function to determine if it is a power of two.Example 1:Input: 1Output: true Explanation: 20 = 1Example 2:Input: 16Output: trueExplanation: 24 = 16Exampl...原创 2018-12-13 16:09:41 · 190 阅读 · 0 评论 -
LeetCode刷题EASY篇Invert Binary Tree
题目Invert a binary tree.Example:Input: 4 / \ 2 7 / \ / \1 3 6 9Output: 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired by this or...原创 2018-12-13 14:36:50 · 220 阅读 · 0 评论 -
LeetCode刷题Easy篇Word Pattern
题目Given a pattern and a string str, find if str follows the same pattern.Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in str.Ex...原创 2018-12-19 11:33:31 · 211 阅读 · 0 评论 -
LeetCode刷题Easy篇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:Y...原创 2018-12-19 11:04:35 · 158 阅读 · 0 评论 -
LeetCode刷题Easy篇First Bad Version
题目You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality check. Since each version is developed based on...原创 2018-12-18 19:26:46 · 246 阅读 · 0 评论 -
LeetCode刷题Easy篇Missing Number
题目Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.Example 1:Input: [3,0,1]Output: 2Example 2:Input: [9,6,4,2,3,5,7,0,...原创 2018-12-18 11:47:52 · 188 阅读 · 0 评论 -
LeetCode刷题Easy篇 Add Digits
题目Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.Example:Input: 38Output: 2 Explanation: The process is like: 3 + 8 = 11, 1 + 1 = 2. ...原创 2018-12-18 10:57:25 · 177 阅读 · 0 评论 -
LeetCode刷题Easy篇Binary Tree Paths
题目Given a binary tree, return all root-to-leaf paths.Note: A leaf is a node with no children.Example:Input: 1 / \2 3 \ 5Output: ["1->2->5", "1->3"]Explanation: All...原创 2018-12-18 10:41:22 · 183 阅读 · 0 评论 -
LeetCode刷题Easy篇.Valid Anagram
题目Given two strings s and t , write a function to determine if t is an anagram of s.Example 1:Input: s = "anagram", t = "nagaram"Output: trueExample 2:Input: s = "rat", t = "car"Output:...原创 2018-12-14 15:48:15 · 199 阅读 · 0 评论 -
LeetCode刷题Easy篇删除单链表中的元素Delete Node in a Linked List
题目Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Given linked list -- head = [4,5,1,9], which looks like following: 4 -> 5 -&g...原创 2018-12-14 15:06:07 · 240 阅读 · 0 评论 -
LeetCode刷题Easy篇.Lowest Common Ancestor of a Binary Search Tree
题目Given a binary search tree (BST), find the lowest common ancestor (LCA) of two given nodes in the BST.According to the definition of LCA on Wikipedia: “The lowest common ancestor is defined betw...原创 2018-12-14 11:33:59 · 182 阅读 · 0 评论 -
LeetCode刷题Easy篇 Balanced Binary Tree
题目Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as:a binary tree in which the depth of the two subtrees of every node never ...原创 2018-12-04 18:56:39 · 205 阅读 · 0 评论 -
LeetCode刷题Easy篇Convert Sorted Array to Binary Search Tree
题目Given an array where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of...原创 2018-12-04 14:02:27 · 196 阅读 · 0 评论 -
LeetCode刷题Easy篇Binary Tree Level Order Traversal II
题目Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left to right, level by level from leaf to root).For example:Given binary tree [3,9,20,null,null,...原创 2018-12-04 10:55:15 · 206 阅读 · 2 评论 -
LeetCode刷题Easy篇判断一个二叉树是否对称
题目Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree [1,2,2,3,4,4,3] is symmetric: 1 / \ 2 2 / \ / \3 4 4 ...原创 2018-11-29 16:12:40 · 528 阅读 · 0 评论 -
LeetCode刷题Easy篇二叉树遍历
题目二叉树的前序,中序,后序遍历Depth First Traversals:(a) Inorder (Left, Root, Right) : 4 2 5 1 3(b) Preorder (Root, Left, Right) : 1 2 4 5 3(c) Postorder (Left, Right, Root) : 4 5 2 3 1Breadth First or L...原创 2018-11-23 17:15:12 · 287 阅读 · 0 评论 -
LeetCode刷题Easy篇两个二叉树是否相同
题目Given two binary trees, write a function to check if they are the same or not.Two binary trees are considered the same if they are structurally identical and the nodes have the same value.Exam...原创 2018-11-23 15:12:43 · 265 阅读 · 0 评论 -
LeetCode刷题Easy篇反转单链表
题目Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULLFollow up:A linked list can be reversed either iteratively or rec...原创 2018-11-22 19:35:49 · 223 阅读 · 0 评论 -
LeetCode刷题Easy篇合并两个有序数组
题目Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.Note:The number of elements initialized in nums1 and nums2 are m and n respectively. You may assume...原创 2018-11-22 17:30:31 · 231 阅读 · 0 评论 -
LeetCode刷题Easy篇两个二进制字符串相加,“和”也是二进制字符串
题目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"...原创 2018-11-21 17:57:43 · 472 阅读 · 0 评论 -
LeetCode刷题Easy篇斐波那契数列问题(递归,尾递归,非递归和动态规划解法)
题目斐波那契数列: f(n)=f(n-1)+f(n-2)(n>2) f(1)=1;f(2)=1;即有名的兔子繁衍问题 1 1 2 3 5 8 13 21 ....我的解法递归package com.puhui.goosecard.manage;/** * 2 * @Author: kerry * 3 * @Date: 2018/12/7 10:18 * 4...原创 2018-11-21 11:35:46 · 982 阅读 · 1 评论 -
LeetCode刷题Easy篇爬楼梯问题(递归和动态规划问题)
题目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 posi...原创 2018-11-20 16:48:56 · 771 阅读 · 0 评论 -
LeetCode刷题Easy篇移除有序链表中的重复元素
题目Given a sorted linked list, delete all duplicates such that each element appear only once.Example 1:Input: 1->1->2Output: 1->2Example 2:Input: 1->1->2->3->3Output...原创 2018-11-20 11:47:21 · 292 阅读 · 0 评论 -
LeetCode刷题Easy篇寻找最后一个字符串的长度
题目Given a stringsconsists 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 d...原创 2018-11-20 11:16:05 · 219 阅读 · 0 评论 -
LeetCode刷题Easy篇寻找最大和的连续子数组(kadane算法和动态规划)
题目Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.Example:Input: [-2,1,-3,4,-1,2,1,-5,4],Output: 6Ex...原创 2018-11-16 17:55:48 · 1073 阅读 · 0 评论 -
LeetCode刷题Easy篇寻找元素插入位置
题目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 arra...原创 2018-11-14 11:27:40 · 209 阅读 · 0 评论 -
LeetCode刷题Easy篇实现java里面的indexOf方法
题目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: 2Exa...原创 2018-11-14 10:27:58 · 269 阅读 · 0 评论 -
LeetCode刷题Easy篇移除数组中为指定数值的所有元素
题目Given an array nums and a value val, remove all instances of that value in-place and return the new length.Do not allocate extra space for another array, you must do this by modifying the input ...原创 2018-11-13 15:29:53 · 286 阅读 · 0 评论 -
LeetCode刷题Easy篇删除有序数组中的重复元素
题目Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this by mod...原创 2018-11-13 14:47:04 · 286 阅读 · 0 评论 -
LeetCode刷题EASY篇罗马数字转换为整型数字表示
题目Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not IIII. Instead, the number four is written as IV. Because the one is before the five ...原创 2018-11-08 11:15:55 · 251 阅读 · 0 评论 -
LeetCode刷题EASY篇有效的插入符
题目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 ...原创 2018-11-08 13:56:44 · 258 阅读 · 0 评论 -
LeetCode刷题MEDIM篇线性时间查找整型数组中最大的k个数
题目一个整数数组,n个元素,寻找最大的m个数,时间复杂度为O(n) 分析以前美团面试问过,后来也没有研究一下,现在学习一下解题思路。最大的n个,显然其他的不关系,n个元素之间的关系也不关心,考虑用快速排序,因为快速排序一遍之后,privotkey对应的元素就是第privotkey大的元素。对了,这里说的第几大貌似不是正确的意思,是从小开始数的第几大,没有关系,为了代码方便实现,...原创 2018-11-07 17:11:12 · 355 阅读 · 0 评论 -
LeetCode刷题EASY篇寻找多个字符串的最长公共前缀
题目Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string "".Example 1:Input: ["flower","flow","flight"]Out...原创 2018-11-06 12:06:04 · 858 阅读 · 0 评论 -
leetcode刷题之EASY篇什么是尾部递归
Consider a simple function that adds the first N integers. (e.g. sum(5) = 1 + 2 + 3 + 4 + 5 = 15).Here is a simple JavaScript implementation that uses recursion:function recsum(x) { if (x===1...原创 2018-11-05 18:54:38 · 187 阅读 · 0 评论 -
LeetCode刷题EASY篇合并两个有序的链表
题目Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Example:Input: 1->2->4, 1->3->4Output...原创 2018-11-06 11:29:30 · 430 阅读 · 0 评论 -
LeetCode刷题Medium篇寻找字符串中最长的回文子串(动态规划解法)
题目Given a strings, find the longest palindromic substring ins. You may assume that the maximum length ofsis 1000.Example 1:Input: "babad"Output: "bab"Note: "aba" is also a valid answer....原创 2018-10-31 19:52:27 · 1119 阅读 · 0 评论 -
java架构篇NodeJS,Vue,前后端分离都是什么鬼
1.Node.JSnode.js是开源的,跨平台的,浏览器之外的Js运行环境。前后端统一语言开发。主要特点事件驱动 异步IO 基于Google的V8引擎,V8引擎执行Javascript的速度非常快,性能非常好 单线程,单进程优点:容易学习,全栈开发----统一语言 高并发----异步IO 高性能 ---JS直接转换为机器码,处理性能更高 高吞吐量和扩展性 适合IO密集...原创 2018-10-29 12:07:28 · 2423 阅读 · 0 评论