Java
文章平均质量分 60
耀凯考前突击大师
路漫漫其修远兮,吾将上下而求索。
展开
-
Java中取得数组中最大(小)元素的几种实现方法
简介本篇文章将主要介绍获取数组中最大(小)元素的基本方法,以及其在Java中的几种实现方法。算法取得数组中最大(小)元素的基本算法一般都类似于如下所示:SET MAX to array[0]FOR i = 1 to array.length - 1 IF array[i] > MAX THEN SET MAX to array[i] ENDIFE...原创 2019-06-30 09:14:20 · 2122 阅读 · 0 评论 -
LeetCode678. Valid Parenthesis String
678. Valid Parenthesis String原创 2017-09-29 13:21:21 · 678 阅读 · 0 评论 -
Leetcode407. Trapping Rain Water II
Leetcode407. Trapping Rain Water II原创 2017-09-21 03:53:16 · 470 阅读 · 0 评论 -
LeetCode677. Map Sum Pairs
LeetCode677. Map Sum Pairs原创 2017-09-28 16:14:37 · 461 阅读 · 0 评论 -
Leetcode282. Expression Add Operators
AnalysisOveiously, in order to solve this question, we have to iterate through all of the possible cases at least once. DFS can be used to solve the iteration process. The optimization we could made it原创 2017-09-20 10:05:46 · 470 阅读 · 0 评论 -
Google OA题目:给出使得字符串B成为字符串A重复自己构成的字符串的子字符串,字符串A最少需重复的次数
Google OA题目:给出使得字符串B成为字符串A重复自己构成的字符串的子字符串,字符串A最少需重复的次数原创 2017-09-12 06:49:38 · 2462 阅读 · 0 评论 -
Simulate Rate limit process based on webserver logs
RateLimiter原创 2017-09-19 08:27:03 · 592 阅读 · 0 评论 -
n个人从m个啤酒龙头接啤酒,需要多久接完?
题目 酒馆里酒馆里有m个龙头可供顾客们接啤酒,每个龙头每秒的出酒量相等,都是1。现有n名顾客准备接酒,他们初始的接酒顺序已经确定。将这些顾客按接酒顺序从1到n编号,i号顾客的接酒量为w[i]。需多久全部用户都能接完?原创 2017-09-17 10:51:06 · 1091 阅读 · 0 评论 -
LeetCode148. Sort List
LeetCode148. Sort List原创 2017-09-25 11:44:28 · 300 阅读 · 0 评论 -
约瑟夫环报数,直到剩下k-1人停止
题目 有n个囚犯围成一圈从1到n编号,并从1开始报数。每当报到k,这个囚犯就会被执行死刑。接着从下一个人开始,剩下的囚犯继续从1开始报数并重复这个过程。直到所有囚犯的数目加起来小于k。问给定n和k,初始站在什么位置的囚犯能活下来?原创 2017-09-17 07:23:48 · 1014 阅读 · 0 评论 -
找出字符串中的最长连续数字子串
给出一个字符串作为输入,找出其中最长的连续数字串并返回其长度和起始index。原创 2017-09-16 02:33:38 · 7446 阅读 · 1 评论 -
Amazon面试题 实现有符号整数的二进制表示法
实现有符号整数的二进制表示法。或者说,实现java.lang.Integer.toBinaryString()方法。要想实现有符号整数的二进制表示法,我们首先需要知道有符号整数在计算机中是怎么存储的。计算机中存储有符号整数,使用的是补码(two’s complement)。正数的补码同原码(其二进制表示)相同。负数的补码是其绝对值的原码按位取反(反码,one’s complement)后再加一。因原创 2017-08-07 07:28:08 · 813 阅读 · 0 评论 -
LeetCode543. Diameter of Binary Tree
Leetcode543. Diameter of Binary Tree原创 2017-10-09 15:34:10 · 440 阅读 · 0 评论 -
LeetCode681. Next Closest Time
681. Next Closest Time原创 2017-10-01 06:25:31 · 1628 阅读 · 0 评论 -
深入解析基数排序(Radix sort)——线性时间排序算法
简介众所周知,常见的排序算法例如快速排序,归并排序等都是基于比较的排序算法。正是因为它们基于比较的特性,这些算法在时间复杂度方面无法做到比O(n*logn)更好。关于这些排序算法的细节在本文中不做讨论,请参考作者之前的一篇文章搜索和排序算法总结。早在1887年,基数排序算法就已经由Herman Hollerith提出,用来解决编表机上的数字排序问题。它实际上是最早被提出的排序算法。基数排序是...原创 2019-07-02 08:25:04 · 1915 阅读 · 0 评论 -
深入解析Bellman Ford's Algorithm,高效解决含有负权重图中的最短路径问题
概述Bellman Ford算法可以用来解决加权图中的最短路径问题。其与Dijkstra算法的区别在于Belllman Ford算法的应用范围更广,例如其可以用来处理带有负权重的加权图中的最短路径问题。由于Dijkstra算法本质上是一种贪心算法,因而当图中存在路径权值之和为负的环时,Dijkstra算法会给出错误的结果因为其总是偏向于选择当前情况下的局部最优路径。Bellman Ford算法的...原创 2019-03-18 16:48:39 · 2098 阅读 · 1 评论 -
Next Permutation Algorithm,取得全排列中当前排列的下一个排列
Next Permutation算法给定一个整数数组,数组中的每一个元素均为0~9之间的整数,如下算法能够高效取得在该数组按数字从小到大排列的全排列中的下一个排列。给定一个任意整数数字,该算法亦可以用来找到仅使用该整数中的数字重构能够得到的 最小的 比当前数字大的数字。假定输入数组为nums。找出当前数组中的 第一个 满足nums[k] < nums[k + 1]条件的索引k。如果满...原创 2019-03-21 16:59:56 · 364 阅读 · 0 评论 -
深入理解拓扑排序(Topological sort)
什么是拓扑排序?维基百科对于拓扑排序有如下定义: a topological sort or topological ordering of a directed graph is a linear ordering of its vertices such that for every directed edge uv from vertex u to vertex v, u com...原创 2018-03-28 08:31:20 · 2923 阅读 · 0 评论 -
线段树(segment tree),看这一篇就够了
定义线段树(segment tree),顾名思义, 是用来存放给定区间(segment, or interval)内对应信息的一种数据结构。与树状数组(binary indexed tree)相似,线段树也用来处理数组相应的区间查询(range query)和元素更新(update)操作。与树状数组不同的是,线段树不止可以适用于区间求和的查询,也可以进行区间最大值,区间最小值(Range Mi...原创 2018-03-18 13:10:49 · 52757 阅读 · 6 评论 -
树状数组(Binary Indexed Tree),看这一篇就够了
定义根据维基百科的定义: A Fenwick tree or binary indexed tree is a data structure that can efficiently update elements and calculate prefix sums in a table of numbers.也就是说,所谓树状数组,或称Binary Indexed Tree,...原创 2018-03-09 07:17:35 · 53017 阅读 · 6 评论 -
LeetCode689. Maximum Sum of 3 Non-Overlapping Subarrays
LeetCode689. Maximum Sum of 3 Non-Overlapping Subarrays原创 2017-10-16 13:27:00 · 2004 阅读 · 0 评论 -
LeetCode636. Exclusive Time of Functions
636. Exclusive Time of Functions原创 2017-10-13 16:37:25 · 446 阅读 · 0 评论 -
LeetCode653. Two Sum IV - Input is a BST
Leetcode 653. Two Sum IV - Input is a BST原创 2017-10-04 15:43:54 · 501 阅读 · 0 评论 -
LeetCode341. Flatten Nested List Iterator
LeetCode341. Flatten Nested List Iterator原创 2017-10-10 16:10:18 · 566 阅读 · 0 评论 -
LeetCode673. Number of Longest Increasing Subsequence
673. Number of Longest Increasing Subsequence原创 2017-10-02 05:01:53 · 696 阅读 · 0 评论 -
[Leetcode]295. Find Median from Data Stream
Leetcode 295. Find Median from Data Stream原创 2017-08-06 07:26:26 · 717 阅读 · 0 评论 -
Trie(字典树)的Java实现
Trie(字典树,单词查找树)的java实现。原创 2017-08-04 13:14:55 · 1839 阅读 · 0 评论 -
二叉搜索树的插入和删除结点操作以及iterator的构造
本文总结了二叉搜索树的插入和删除以及DFS遍历iterator的构造操作并给出了相应的java代码原创 2016-07-23 14:44:55 · 614 阅读 · 0 评论 -
Facebook面试题 Find first k common elements in n sorted arrays
Given n sorted arrays, find first k common elements in them. E.g. the common elements of {{1,3,5,7}, {3,4,5,6}, {3,5,6,8,9}, {2,3,4,5,11,18}} are 3 and 5. Analysis: In order to solve this question原创 2016-12-30 07:03:02 · 1537 阅读 · 0 评论 -
Facebook 面试题 Binary tree inorder successor
给定一个二叉树,每一个结点都有指向其父节点的指针。求这个结点的inorder successor。原创 2017-01-06 15:02:36 · 1508 阅读 · 0 评论 -
FaceBook面试题 Implement strStrp(String a, String b)
Implement a function strStrp(String a, String b), which returns index where any permutation of b is a substring of a. E.g. strStrp(“hello”, “ell”), return 1; strStrp(“hello”, “lle”), return 1; strS原创 2016-12-29 04:43:13 · 637 阅读 · 0 评论 -
Kth closest points
Given an array containing N points, find the Kth closest points >to the origin in the 2D plane. You can assume K is much >smaller than N and N is very large. Notice that the key requirement here are:”原创 2016-12-27 11:21:57 · 910 阅读 · 0 评论 -
Facebook面试题 Remove duplicates from array where all duplicate numbers are located adjacently
Given an integer array which has the property that all the elements haveing same value are adjacent to each other. e.g. {2,2,2,1,5,6,6,7,7}, output: Remove duplicate element in place and output the原创 2017-01-03 11:38:33 · 568 阅读 · 0 评论 -
[LeetCode]321. Create Maximum Number
参见Github. 321. Create Maximum Number原创 2016-10-25 14:30:22 · 374 阅读 · 0 评论 -
Facebook面试题 check for subText in input text's subarray.
This question is a follow up for question for Suffix array sorting. Based on the output of last question, we are given an input array int[] substext. We want to check for the existance of this subTex原创 2017-01-03 09:23:27 · 369 阅读 · 0 评论 -
Facebook面试题 Suffix array sorting
Given a suffix array. E.g. int[] text = {10, 20, 30, 25}, then suffix[0] = {10, 20, 30, 25}, suffix[1] = {20, 30, 25}, succix[2] = {30, 25}, suffix[3] = {25}. Then sort those arrays using lexical orde原创 2017-01-02 13:37:39 · 773 阅读 · 0 评论 -
Java Integer的==和.equals()之间的区别
在Java1.5及以上的版本中,由于autoboxing机制,Integer和int在很多情况下可以直接相互转换。 那么其中的一个常见的问题就是如何判断两个Integer类型变量的值是否相等。 我们知道,Integer是一个引用类型的变量,而int是一个基本类型的变量。对于基本类型变量,==比较的是其值而非地址。而对于引用类型的变量,==和.equals()比较的都是其地址,除非该类对.equa原创 2016-11-22 02:40:33 · 6997 阅读 · 1 评论 -
排序和搜索算法总结
搜索及排序算法的总结原创 2016-10-20 10:17:00 · 678 阅读 · 0 评论 -
Java中Map按value值进行排序
Java中对Map按value值进行排序的两种方法。原创 2016-10-20 05:05:59 · 8140 阅读 · 2 评论 -
Facebook面试题 meeting rooms 求同时最多meeting room的时间
给出会议开始和结束时间,求meeting room interval最多的时间点。返回任意一个时间即可。原创 2017-01-07 15:28:23 · 1859 阅读 · 0 评论