题目大意:
验证回文字符串 III
给出一个字符串 s 和一个整数 k,请你帮忙判断这个字符串是不是一个 K 回文。
如果可以通过从字符串中删去最多 k 个字符将其转换为回文,该字符串是一个 K 回文。
继续阅读题目大意:
验证回文字符串 III
给出一个字符串 s 和一个整数 k,请你帮忙判断这个字符串是不是一个 K 回文。
如果可以通过从字符串中删去最多 k 个字符将其转换为回文,该字符串是一个 K 回文。
继续阅读题目大意:
等差数列中缺失的数字
数组 arr 中的值符合等差数列的数值规律:在 0 <= i < arr.length – 1 的前提下,arr[i+1] – arr[i] 的值都相等。
然后,我们从数组中删去一个 既不是第一个也不是最后一个的值。
给你一个缺失值的数组,请你帮忙找出那个被删去的数字。
题目大意:
安排会议日程
你是一名行政助理,手里有两位客户的空闲时间表:slots1 和 slots2,以及会议的预计持续时间 duration,请你为他们安排合适的会议时间。
「会议时间」是两位客户都有空参加,并且持续时间能够满足预计时间 duration 的 最早的时间间隔。
如果没有满足要求的会议时间,就请返回一个 空数组。
「空闲时间」的格式是 [start, end],由开始时间 start 和结束时间 end 组成,表示从 start 开始,到 end 结束。
题目保证数据有效:同一个人的空闲时间不会出现交叠的情况,也就是说,对于同一个人的两个空闲时间 [start1, end1] 和 [start2, end2],要么 start1 > end2,要么 start2 > end1。
继续阅读题目大意:
你有一大块巧克力,它由一些甜度不完全相同的小块组成。我们用数组 sweetness 来表示每一小块的甜度。
你打算和 K 名朋友一起分享这块巧克力,所以你需要将切割 K 次才能得到 K+1 块,每一块都由一些 连续 的小块组成。
为了表现出你的慷慨,你将会吃掉 总甜度最小 的一块,并将其余几块分给你的朋友们。
请找出一个最佳的切割策略,使得你所分得的巧克力 总甜度最大,并返回这个 最大总甜度。
题目大意:
网页爬虫
Given a url startUrl
and an interface HtmlParser
, implement a web crawler to crawl all links that are under the same hostname as startUrl
.
Return all urls obtained by your web crawler in any order.
Your crawler should:
startUrl
HtmlParser.getUrls(url)
to get all urls from a webpage of given url.startUrl
.As shown in the example url above, the hostname is example.org
. For simplicity sake, you may assume all urls use http protocol without any port specified. For example, the urls http://leetcode.com/problems
and http://leetcode.com/contest
are under the same hostname, while urls http://example.org/test
and http://example.com/abc
are not under the same hostname.
The HtmlParser
interface is defined as such:
interface HtmlParser { // Return a list of all urls from a webpage of given url. public List<String> getUrls(String url); }
Below are two examples explaining the functionality of the problem, for custom testing purposes you’ll have three variables urls
, edges
and startUrl
. Notice that you will only have access to startUrl
in your code, while urls
and edges
are not directly accessible to you in code.
题目大意:
多线程网页爬虫
Given a url startUrl
and an interface HtmlParser
, implement a Multi-threaded web crawler to crawl all links that are under the same hostname as startUrl
.
Return all urls obtained by your web crawler in any order.
Your crawler should:
startUrl
HtmlParser.getUrls(url)
to get all urls from a webpage of given url.startUrl
.As shown in the example url above, the hostname is example.org
. For simplicity sake, you may assume all urls use http protocol without any port specified. For example, the urls http://leetcode.com/problems
and http://leetcode.com/contest
are under the same hostname, while urls http://example.org/test
and http://example.com/abc
are not under the same hostname.
The HtmlParser
interface is defined as such:
interface HtmlParser { // Return a list of all urls from a webpage of given url. // This is a blocking call, that means it will do HTTP request and return when this request is finished. public List<String> getUrls(String url); }
Note that getUrls(String url)
simulates performing a HTTP request. You can treat it as a blocking function call which waits for a HTTP request to finish. It is guaranteed that getUrls(String url)
will return the urls within 15ms. Single-threaded solutions will exceed the time limit so, can your multi-threaded web crawler do better?
Below are two examples explaining the functionality of the problem, for custom testing purposes you’ll have three variables urls
, edges
and startUrl
. Notice that you will only have access to startUrl
in your code, while urls
and edges
are not directly accessible to you in code.
Follow up:
题目大意:
数组变换
首先,给你一个初始数组 arr。然后,每天你都要根据前一天的数组生成一个新的数组。
第 i 天所生成的数组,是由你对第 i-1 天的数组进行如下操作所得的:
过些时日,你会发现数组将会不再发生变化,请返回最终所得到的数组。
题目大意:
设计排行榜
请你帮忙来设计这个 Leaderboard 类,使得它有如下 3 个函数:
addScore(playerId, score):
假如参赛者已经在排行榜上,就给他的当前得分增加 score 点分值并更新排行。
假如该参赛者不在排行榜上,就把他添加到榜单上,并且将分数设置为 score。
top(K):返回前 K 名参赛者的得分总和。
reset(playerId):将指定参赛者的成绩清零。题目保证在调用此函数前,该参赛者已有成绩,并且在榜单上。
初始状态下,排行榜是空的。
继续阅读