- 博客(39)
- 资源 (7)
- 收藏
- 关注
原创 leetcode 383. Ransom Note
Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; ot
2017-06-30 16:43:34 253
原创 leetcode 563. Binary Tree Tilt
Given a binary tree, return the tilt of the whole tree.The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum of all right subtre
2017-06-30 16:19:58 453
原创 leetcode 453. Minimum Moves to Equal Array Elements
Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements by 1.Example:Input:[1,2,3]Ou
2017-06-30 15:44:37 269
原创 ArrayList<Integer>如何转换为int[]数组
网上搜Arraylist和数组互相转换的方法时,举的例子都是String类型的。比如:但是对于int类型如果这样写:ArrayList a=new ArrayList();int[] array=(int[])a.toArray(new int[size]);//会报错则会报错,这是因为int[]并不等同于Integer[]。因此如果换成Integer[]数组,则能正确运行。
2017-06-29 17:13:49 101500 13
转载 HashMap和HashSet的区别
转自http://www.importnew.com/6931.htmlHashMap和HashSet的区别是Java面试中最常被问到的问题。如果没有涉及到Collection框架以及多线程的面试,可以说是不完整。而Collection框架的问题不涉及到HashSet和HashMap,也可以说是不完整。HashMap和HashSet都是collection框架的一部分,它们让我们能够使
2017-06-29 16:57:39 13541 1
原创 leetcode 349. Intersection of Two Arrays
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note:Each element in the result must be unique.The res
2017-06-29 16:54:04 285
原创 leetcode 455. Assign Cookies
Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a c
2017-06-29 14:41:21 271
原创 leetcode 530. Minimum Absolute Difference in BST
Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes.Example:Input: 1 \ 3 / 2Output:1Explanation:Th
2017-06-28 14:37:50 383
原创 leetcode 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 number
2017-06-28 13:57:38 282
原创 leetcode 503. Next Greater Element II
Given a circular array (the next element of the last element is the first element of the array), print the Next Greater Number for every element. The Next Greater Number of a number x is the first gre
2017-06-27 17:18:11 255
原创 leetcode 347. Top K Frequent Elements
Given a non-empty array of integers, return the k most frequent elements.For example,Given [1,1,1,2,2,3] and k = 2, return [1,2].Note: You may assume k is always valid, 1 ≤ k ≤ number
2017-06-27 15:40:12 345
原创 leetcode 238. Product of Array Except Self
Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O
2017-06-27 13:49:49 387
原创 leetcode 598. Range Addition II
Given an m * n matrix M initialized with all 0's and several update operations.Operations are represented by a 2D array, and each operation is represented by an array with two positive integers a
2017-06-26 17:14:24 275
转载 并查集详解 (转)
这个文章是几年前水acm的时候转的, 当时也不知道作者是谁, 要是有人知道的话说一下吧 转载地址http://blog.csdn.net/dellaserss/article/details/7724401/并查集是我暑假从高手那里学到的一招,觉得真是太精妙的设计了。以前我无法解决的一类问题竟然可以用如此简单高效的方法搞定。不分享出来真是对不起party了。(party:我靠,
2017-06-26 16:38:10 239
原创 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, the
2017-06-26 16:22:48 594
原创 leetcode 599. Minimum Index Sum of Two Lists
Suppose Andy and Doris want to choose a restaurant for dinner, and they both have a list of favorite restaurants represented by strings.You need to help them find out their common interest with th
2017-06-26 14:34:52 431
转载 经典算法系-并查集(Union-Find Sets)
1. 并查集(Union-Find Sets) 一种树型数据结构,用于处理不相交集合(Disjoint Sets)的合并以及查询;一开始让所有元素独立成树,也就是只有根节点的树;然后根据需要将关联的元素(树)进行合并;合并的方式仅仅是将一棵树最原始的节点的父亲索引指向另一棵树; 优化:加入一个rank数组存储节点深度的下界(从当前节点到其最远子节点的距离),从而可以启发式的
2017-06-25 19:11:34 786
原创 leetcode 565. Array Nesting
A zero-indexed array A consisting of N different integers is given. The array contains all integers in the range [0, N - 1].Sets S[K] for 0 S[K] = { A[K], A[A[K]], A[A[A[K]]], ... }.Sets S
2017-06-25 17:25:36 1878
原创 leetcode 623. Add One Row to Tree
Given the root of a binary tree, then value v and depth d, you need to add a row of nodes with value v at the given depth d. The root node is at depth 1.The adding rule is: given a positive in
2017-06-25 14:40:54 826
原创 leetcode 492. Construct the Rectangle
For a web developer, it is very important to know how to design a web page's size. So, given a specific rectangular web page’s area, your job by now is to design a rectangular web page, whose length L
2017-06-25 14:14:52 245
原创 leetcode 283. 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.For example, given nums = [0, 1, 0, 3, 12], after calling you
2017-06-22 16:24:23 277
转载 一步一步理解线段树
目录一、概述二、从一个例子理解线段树 创建线段树 线段树区间查询 单节点更新 区间更新三、线段树实战--------------------------一 概述线段树,类似区间树,它在各个节点保存一条线段(数组中的一段子数组),主要用于高效解决连续区间的动态查询问题,由于二叉结构的特性,它基本能保持每个操作的复
2017-06-20 00:22:17 238
原创 51Nod 加农炮
一个长度为M的正整数数组A,表示从左向右的地形高度。测试一种加农炮,炮弹平行于地面从左向右飞行,高度为H,如果某处地形的高度大于等于炮弹飞行的高度H(A[i] >= H),炮弹会被挡住并落在i - 1处,则A[i - 1] + 1。如果H 所有的A[i],这个炮弹也无效。现在给定N个整数的数组B代表炮弹高度,计算出最后地形的样子。例如:地形高度A = {1, 2, 0, 4, 3, 2, 1
2017-06-19 23:57:23 446
原创 Java中PriorityQueue的排序
PrioriryQueue是Queue接口的一个队列实现类,但它的排序并不是典型的队列式先进先出(FIFO)的方式。PriorityQueue的排序方式分为两种,一种是自然排序,这是按照加入元素的大小从小到大排序的。第二种是定制排序,是使用comparator类来重写compare(Object o1,Object o2)方法来实现定制排序的。但是这些都不是关键,关键在于PriorityQ
2017-06-18 16:46:06 7539
原创 51Nod 消灭兔子
有N只兔子,每只有一个血量B[i],需要用箭杀死免子。有M种不同类型的箭可以选择,每种箭对兔子的伤害值分别为D[i],价格为P[i](1 特别说明:1、当箭的伤害值大于等于兔子的血量时,能将兔子杀死;2、血量B[i],箭的伤害值D[i],箭的价格P[i],均小于等于100000。Input第1行:两个整数N,M,中间用空格分隔(1 第2 - N + 1行:每行1个正整数(共
2017-06-18 16:30:31 379
转载 准确删除List中的整数值
List为移除数据提供了两个remove的方法:1. 按照下标索引删除2. 按照值删除,删除第一个符合的值对象。public interface List extends Collection { //省略其它方法,只保留remove方法 /** * Removes the first occurrence of the specified element
2017-06-15 00:32:33 2078
原创 51Nod 数据流中的算法
51nod近日上线了用户满意度检测工具,使用高级人工智能算法,通过用户访问时间、鼠标轨迹等特征计算用户对于网站的满意程度。现有的统计工具只能统计某一个窗口中,用户的满意程度的均值。夹克老爷想让你为统计工具添加一个新feature,即在统计均值的同时,计算窗口中满意程度的标准差和中位数(均值需要向下取整)。Input第一行是整数n与k,代表有n次操作,时间窗口大小为k。 (1
2017-06-15 00:13:51 785
原创 51Nod 斜率最大
平面上有N个点,任意2个点确定一条直线,求出所有这些直线中,斜率最大的那条直线所通过的两个点。(点的编号为1-N,如果有多条直线斜率相等,则输出所有结果,按照点的X轴坐标排序,正序输出。数据中所有点的X轴坐标均不相等)Input第1行,一个数N,N为点的数量。(2 <= N <= 10000)第2 - N + 1行:具体N个点的坐标,X Y均为整数(-10^9
2017-06-14 14:53:45 489
原创 51Nod 独木舟
n个人,已知每个人体重。独木舟承重固定,每只独木舟最多坐两个人,可以坐一个人或者两个人。显然要求总重量不超过独木舟承重,假设每个人体重也不超过独木舟承重,问最少需要几只独木舟?Input第一行包含两个正整数n (0<n<=10000)和m (0<m<=2000000000),表示人数和独木舟的承重。接下来n行,每行一个正整数,表示每个人的体重。体重不超过1000000
2017-06-14 00:53:04 292
原创 51Nod 扔盘子
有一口井,井的高度为N,每隔1个单位它的宽度有变化。现在从井口往下面扔圆盘,如果圆盘的宽度大于井在某个高度的宽度,则圆盘被卡住(恰好等于的话会下去)。盘子有几种命运:1、掉到井底。2、被卡住。3、落到别的盘子上方。盘子的高度也是单位高度。给定井的宽度和每个盘子的宽度,求最终落到井内的盘子数量。如图井和盘子信息如下:井:5 6 4 3 6 2 3盘子:2
2017-06-13 12:01:53 709
原创 51Nod 走格子
有编号1-n的n个格子,机器人从1号格子顺序向后走,一直走到n号格子,并需要从n号格子走出去。机器人有一个初始能量,每个格子对应一个整数A[i],表示这个格子的能量值。如果A[i] > 0,机器人走到这个格子能够获取A[i]个能量,如果A[i] < 0,走到这个格子需要消耗相应的能量,如果机器人的能量 < 0,就无法继续前进了。问机器人最少需要有多少初始能量,才能完成整个旅程。例如:n
2017-06-12 17:59:57 465
原创 51Nod 数字1的数量
给定一个十进制正整数N,写下从1开始,到N的所有正数,计算出其中出现所有1的个数。例如:n = 12,包含了5个1。1,10,12共包含3个1,11包含2个1,总共5个1。Input输入N(1 Output输出包含1的个数Input示例12Output示例5Java的运行时限为:3000 m
2017-06-12 16:55:54 445
转载 经典排序算法 - 桶排序Bucket sort
补充说明三点1,桶排序是稳定的2,桶排序是常见排序里最快的一种,比快排还要快…大多数情况下3,桶排序非常快,但是同时也非常耗空间,基本上是最耗空间的一种排序算法我自己的理解哈,可能与网上说的有一些出入,大体都是同样的原理无序数组有个要求,就是成员隶属于固定(有限的)的区间,如范围为[0-9](考试分数为1-100等)例如待排数字[6 2 4 1
2017-06-11 23:29:22 1028
原创 leetcode 451. Sort Characters By Frequency
Given a string, sort it in decreasing order based on the frequency of characters.Example 1:Input:"tree"Output:"eert"Explanation:'e' appears twice while 'r' and 't' both appear once.So 'e
2017-06-11 23:21:46 238
原创 leetcode 260. 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:Given
2017-06-11 17:03:47 286
原创 leetcode 258. Add Digits
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has on
2017-06-11 15:05:40 269
原创 leetcode 226. Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1我想法就是用递归,然后引用交换每个结点的左右子树。public class Invert_Binary_Tree_226 { public
2017-06-06 20:51:33 227
原创 leetcode 462. Minimum Moves to Equal Array Elements II
Given a non-empty integer array, find the minimum number of moves required to make all array elements equal, where a move is incrementing a selected element by 1 or decrementing a selected element by
2017-06-05 21:03:06 307
转载 求一个数组中第k大的数方法
求一个数组中第k大的数,我第一印象是冒泡,因为只要冒泡k趟即可,第一趟冒泡第一大,第二次冒泡第二大,第k次冒泡第k大,时间复杂度为O(kn),n为数组长度。但是我们都知道快速排序是对冒泡的改进,降低冒泡的递归深度,使时间复杂度降低到O(nlgn),为什么不用快排呢?那么快排的时间复杂度又是多少呢?利用了 quicksort 和二分查找 的做法。先把数组分成两个部分,左边一个部分比pivot
2017-06-05 20:16:41 2051
[数学建模方法与分析].(新西兰)Mark.M.Meerschaert.清晰PDF版
2017-09-15
有名的combobox下拉框插件压缩后的js版本
2016-09-23
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人