算法
文章平均质量分 77
帘外雨
学生一枚
展开
-
LeetCode 667. Beautiful Arrangement II
Given two integers n and k, you need to construct a list which contains n different positive integers ranging from 1 to n and obeys the following requirement: Suppose this list is [a1, a2, a3, … , an],原创 2017-09-01 20:54:23 · 714 阅读 · 0 评论 -
网易2018校招编程题
一个合法的括号匹配序列被定义为: 1. 空串”“是合法的括号序列 2. 如果”X”和”Y”是合法的序列,那么”XY”也是一个合法的括号序列 3. 如果”X”是一个合法的序列,那么”(X)”也是一个合法的括号序列 4. 每个合法的括号序列都可以由上面的规则生成 例如”“, “()”, “()()()”, “(()())”, “(((()))”都是合法的。 从一个字符串S中移除零个或者多个字符得到的序列原创 2017-09-10 13:08:28 · 2273 阅读 · 0 评论 -
网易2018年编程题
魔法王国一共有n个城市,编号为0~n-1号,n个城市之间的道路连接起来恰好构成一棵树。 小易现在在0号城市,每次行动小易会从当前所在的城市走到与其相邻的一个城市,小易最多能行动L次。 如果小易到达过某个城市就视为小易游历过这个城市了,小易现在要制定好的旅游计划使他能游历最多的城市,请你帮他计算一下他最多能游历过多少个城市(注意0号城市已经游历了,游历过的城市不重复计算)。输入描述: 输入包括两行,第原创 2017-09-10 11:42:07 · 4145 阅读 · 0 评论 -
LeetCode: 421. Maximum XOR of Two Numbers in an Array
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231.Find the maximum result of ai XOR aj, where 0 ≤ i, j < n.Could you do this in O(n) runtime?Example: Input: [3, 10, 5, 25, 2,原创 2017-09-15 15:13:21 · 244 阅读 · 0 评论 -
LeetCode:529. Minesweeper
Let’s play the minesweeper game (Wikipedia, online game)! You are given a 2D char matrix representing the game board. ‘M’ represents an unrevealed mine, ‘E’ represents an unrevealed empty square, ‘B’ r原创 2017-09-13 09:35:25 · 212 阅读 · 0 评论 -
生活中的刺激——2016/06/09
难得的机会被错失,感觉还是自己水平不够,同时由于自己的心理不够强大,面对紧张时,脑子里会一片空白。并且,我不习惯将自己不成熟的思考表述出来,临场表现能力欠缺,有待改善。 下面记录一下遇到的卡住我的那道面试题: 小A和小B玩游戏,游戏设置有一个非负整数数组nums和一个非负整数target。小A要想赢必须要从数组中挑出一组不少于2个的数字,使得所挑出的数按位相或能够得到target。而小B若想赢,原创 2017-06-12 10:59:14 · 341 阅读 · 0 评论 -
数据结构之并查集
一、并查集定义 并查集是一种树型的数据结构,用于处理一些不相交集合(Disjoint Sets)的合并及查询问题。常常在使用中以森林来表示。集就是让每个元素构成一个单元素的集合,也就是按一定顺序将属于同一组的元素所在的集合合并。 并查集本质上也是一个集合,集合则表示其中的元素没有顺序关系,之所以用森林表示是为了尽快确定两个元素是否属于同一个集合,当两个原创 2017-04-26 17:23:09 · 377 阅读 · 0 评论 -
算法进阶之动态规划
March 26, 2013作者:Hawstein 出处:http://hawstein.com/posts/dp-novice-to-advanced.html 声明:本文采用以下协议进行授权: 自由转载-非商用-非衍生-保持署名|Creative Commons BY-NC-ND 3.0 ,转载请注明作者及出处。前言本文翻译自TopCoder上的一篇文章: Dynamic Programmin转载 2017-03-30 19:10:25 · 731 阅读 · 0 评论 -
665. Non-decreasing Array
Given an array with n integers, your task is to check if it could become non-decreasing by modifying at most 1 element.We define an array is non-decreasing if array[i] <= array[i + 1] holds for every i原创 2017-09-01 21:59:01 · 471 阅读 · 0 评论