算法
liboren920528
这个作者很懒,什么都没留下…
展开
-
华为2017实习生招聘笔试题-任务调度
输入:[1.80.1.10]|[2.20.11.15]|[3.50.21.10]|[4.120.31.10]|[5.100.41.10] 输出:0.1|1.10|2.10|3.10|4.10|5.10|2.5|0.144输入:[1.80.0.20]|[2.90.10.20]|[3.100.30.20]|[4.120.40.20]|[5.140.100.10] 输出:1.10|2.20|3.10|原创 2017-04-07 23:25:30 · 781 阅读 · 0 评论 -
KMP算法之我见
KMP算法最核心的是求next数组,然后再根据next数组来进行模式匹配。因此分为两部分:1.求next数组next数组记录的是模式串的特征,即最长相同前后缀考虑如下模式串P:ABCDABC它的前缀有:A,AB,ABC,ABCD,ABCDA,ABCDAB它的后缀有:C,BC,ABC,DABC,CDABC,BCDABC因此它的最长相同前后缀是ABC,长度是3.next数组中p[i]中存的就是模式串p[原创 2017-04-22 00:14:37 · 206 阅读 · 0 评论 -
阿里2017实习生招聘笔试-编程题-逆波兰
思路:很简单,就是一些基本的入栈出栈操作,关键是split(“\s+”)这一步,\s在正则表达式中是匹配任何空白字符,包括空格、制表符、换页符等等,应为\在java中是转义符,所以要打\import java.util.Scanner;import java.util.Stack;public class Main { public static void main(String[] ar原创 2017-04-26 20:59:54 · 440 阅读 · 0 评论 -
阿里2017实习生招聘笔试-编程题-过滤
思路:这是leetcode上的原题leetcode 44. Wildcard Matching主要思想是动态规划public static void main(String[] args){ Scanner sc = new Scanner(System.in); String str = sc.nextLine(); String pattern =原创 2017-04-26 21:04:18 · 632 阅读 · 0 评论 -
滴滴出行2017春招研发工程师笔试题-套娃
思路:二维数组排序+动态规划import java.util.Arrays;import java.util.Comparator;import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in)原创 2017-04-22 20:34:55 · 411 阅读 · 0 评论 -
滴滴出行2017春招研发工程师笔试题-翻转单词顺序
//javapublic static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNext()){ String str = sc.nextLine(); String[] strs = str.trim().s原创 2017-04-22 20:30:21 · 530 阅读 · 1 评论 -
[LeetCode.200]Number of Islands
问题描述 Given a 2d grid map of ‘1’s (land) and ‘0’s (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may a原创 2017-04-22 15:07:22 · 258 阅读 · 0 评论 -
[LeetCode.542]01 Matrix
问题描述 Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell.The distance between two adjacent cells is 1.Example 1: Input:0 0 0 0 1 0 0 0 0Output: 0 0 0 0 1 0 0 0原创 2017-04-22 15:05:22 · 437 阅读 · 0 评论 -
[LeetCode.300]Longest Increasing Subsequence
问题描述 Given an unsorted array of integers, find the length of longest increasing subsequence.For example, Given [10, 9, 2, 5, 3, 7, 101, 18], The longest increasing subsequence is [2, 3, 7, 101], the原创 2017-04-22 15:03:05 · 177 阅读 · 0 评论 -
[LeetCode.368]Largest Divisible Subset
问题描述 Given a set of distinct positive integers, find the largest subset such that every pair (Si, Sj) of elements in this subset satisfies: Si % Sj = 0 or Sj % Si = 0.If there are multiple solutions,原创 2017-04-22 15:01:22 · 223 阅读 · 0 评论 -
网易互联网2017在线笔试题目-魔力手环
题目描述: 小易拥有一个拥有魔力的手环上面有n个数字(构成一个环),当这个魔力手环每次使用魔力的时候就会发生一种奇特的变化:每个数字会变成自己跟后面一个数字的和(最后一个数字的后面一个数字是第一个),一旦某个位置的数字大于等于100就马上对100取模(比如某个位置变为103,就会自动变为3).现在给出这个魔力手环的构成,请你计算出使用k次魔力之后魔力手环的状态。 输入描述: 输入数据包括两行:原创 2017-04-22 14:53:49 · 676 阅读 · 0 评论 -
阿里巴巴集团2017暑期实习Java研发工程师在线编程题-数组分片
题目:一个整型(非负)数组,将其划分为总和相同的4个切片,例如:{2,5,1,1,1,1,4,1,7,3,7},切片操作后划分为:{2,5},{1,1,1,4},{7},{7},也就找到所谓的四等分点,切分点分别是1,1,3,切分点不算在总和内。输出能否分片。要求时间复杂度和空间复杂度为o(n)。思路:两个Map,一个存<总和,位置>,一个存<位置,总和>。由于数组非负,先由头尾指针向中间逼近,原创 2017-04-22 00:59:09 · 811 阅读 · 0 评论 -
堆排序算法实现
堆排序算法代码实现class HeapSort { public static void main(String[] args) { int[] src = {1, 5, 7, 2, 3, 8, 27, 19,1, 5, 7, 2, 3, 8, 27, 19,1, 5, 7, 2, 3, 8, 27, 19,1, 5, 7, 2, 3, 8, 27, 19,1, 5, 7, 2原创 2017-04-22 00:31:32 · 182 阅读 · 0 评论 -
[LeetCode.547]Friend Circles
问题描述: There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is a direct friend of B, and B is a direct friend of C,原创 2017-05-02 18:17:33 · 412 阅读 · 0 评论 -
[Leetcode.467]Unique Substrings in Wraparound String
问题描述Consider the string s to be the infinite wraparound string of “abcdefghijklmnopqrstuvwxyz”, so s will look like this: “…zabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcd….”.Now we have anot原创 2017-04-11 17:51:45 · 294 阅读 · 0 评论 -
华为2017实习生招聘笔试题-公司年会
公司年会 public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); String in = sc.nextLine(); String[] numsOfString = in.split(",");原创 2017-04-07 21:56:42 · 922 阅读 · 0 评论 -
华为2017实习生招聘笔试题-水仙花数
水仙花数 public class Main { public static void main(String[] agrs){ int count = 1; int sum = 0; for(int i = 100; i <= 1000; i++){ if(isFlowerNumber(i)){原创 2017-04-07 21:58:22 · 477 阅读 · 0 评论 -
【面试必看】各种排序算法代码实现
//冒泡排序bubbleSort,时间复杂度O(n^2),空间复杂度O(1),稳定 public static void bubbleSort(int[] arr){ int len = arr.length; for(int i = 0; i < len; i++){ for(int j = 1; j < len - i; j++){原创 2017-07-23 13:02:51 · 258 阅读 · 0 评论