Redtongue

人生苦短,我用Python


  • 首页

  • 归档

  • 分类

  • 标签

  • 关于

  • 搜索

938.Range Sum of BST(二叉搜索树的范围和)

发表于 2018-11-11 | 更新于: 2018-11-11 | 分类于 leetcode

Description

Given the root node of a binary search tree, return the sum of values of all nodes with value between L and R (inclusive).

The binary search tree is guaranteed to have unique values.


给定二叉搜索树的根结点 root,返回 L 和 R(含)之间的所有结点的值的和。

二叉搜索树保证具有唯一的值。

题目链接:https://leetcode.com/problems/range-sum-of-bst/

Difficulty: medium

阅读全文 »

937.Recorder Log Files(重新排列日志文件)

发表于 2018-11-11 | 更新于: 2018-11-11 | 分类于 leetcode

Description

You have an array of logs. Each log is a space delimited string of words.

For each log, the first word in each log is an alphanumeric identifier. Then, either:

  • Each word after the identifier will consist only of lowercase letters, or;
  • Each word after the identifier will consist only of digits.

We will call these two varieties of logs letter-logs and digit-logs. It is guaranteed that each log has at least one word after its identifier.

Reorder the logs so that all of the letter-logs come before any digit-log. The letter-logs are ordered lexicographically ignoring identifier, with the identifier used in case of ties. The digit-logs should be put in their original order.

Return the final order of the logs.


你有一个日志数组 logs。每条日志都是以空格分隔的字串。

对于每条日志,其第一个字为字母数字标识符。然后,要么:

  • 标识符后面的每个字将仅由小写字母组成,或;
  • 标识符后面的每个字将仅由数字组成。

我们将这两种日志分别称为字母日志和数字日志。保证每个日志在其标识符后面至少有一个字。

将日志重新排序,使得所有字母日志都排在数字日志之前。字母日志按字母顺序排序,忽略标识符,标识符仅用于表示关系。数字日志应该按原来的顺序排列。

返回日志的最终顺序。

题目链接:https://leetcode.com/problems/reorder-log-files/

Difficulty: easy

阅读全文 »

DeepInf:Social Influence Prediction with Deep Learning

发表于 2018-11-10 | 更新于: 2018-11-21 | 分类于 paper

结合深度学习预测每个用户的社交影响。

论文地址:https://arxiv.org/abs/1807.05560

ABSTRACT

阅读全文 »

936.Stamping The Sequence(戳印序列)

发表于 2018-11-06 | 更新于: 2018-11-11 | 分类于 leetcode

Description

You want to form a target string of lowercase letters.

At the beginning, your sequence is target.length ‘?’ marks. You also have a stamp of lowercase letters.

On each turn, you may place the stamp over the sequence, and replace every letter in the sequence with the corresponding letter from the stamp. You can make up to 10 * target.length turns.

For example, if the initial sequence is “?????”, and your stamp is “abc”, then you may make “abc??”, “?abc?”, “??abc” in the first turn. (Note that the stamp must be fully contained in the boundaries of the sequence in order to stamp.)

If the sequence is possible to stamp, then return an array of the index of the left-most letter being stamped at each turn. If the sequence is not possible to stamp, return an empty array.

For example, if the sequence is “ababc”, and the stamp is “abc”, then we could return the answer [0, 2], corresponding to the moves “?????” -> “abc??” -> “ababc”.

Also, if the sequence is possible to stamp, it is guaranteed it is possible to stamp within 10 * target.length moves. Any answers specifying more than this number of moves will not be accepted.


你想要用小写字母组成一个目标字符串 target。

开始的时候,序列由 target.length 个 ‘?’ 记号组成。而你有一个小写字母印章 stamp。

在每个回合,你可以将印章放在序列上,并将序列中的每个字母替换为印章上的相应字母。你最多可以进行 10 * target.length 个回合。

举个例子,如果初始序列为 “?????”,而你的印章 stamp 是 “abc”,那么在第一回合,你可以得到 “abc??”、”?abc?”、”??abc”。(请注意,印章必须完全包含在序列的边界内才能盖下去。)

如果可以印出序列,那么返回一个数组,该数组由每个回合中被印下的最左边字母的索引组成。如果不能印出序列,就返回一个空数组。

例如,如果序列是 “ababc”,印章是 “abc”,那么我们就可以返回与操作 “?????” -> “abc??” -> “ababc” 相对应的答案 [0, 2];

另外,如果可以印出序列,那么需要保证可以在 10 * target.length 个回合内完成。任何超过此数字的答案将不被接受。

题目链接:https://leetcode.com/problems/stamping-the-sequence/

Difficulty: hard

阅读全文 »

935.Knight Dialers(骑士拨号器)

发表于 2018-11-06 | 更新于: 2018-11-07 | 分类于 leetcode

Description

A chess knight can move as indicated in the chess diagram below:




This time, we place our chess knight on any numbered key of a phone pad (indicated above), and the knight makes N-1 hops. Each hop must be from one key to another numbered key.

Each time it lands on a key (including the initial placement of the knight), it presses the number of that key, pressing N digits total.

How many distinct numbers can you dial in this manner?

Since the answer may be large, output the answer modulo 10^9 + 7.


国际象棋中的骑士可以按下图所示进行移动:




这一次,我们将 “骑士” 放在电话拨号盘的任意数字键(如上图所示)上,接下来,骑士将会跳 N-1 步。每一步必须是从一个数字键跳到另一个数字键。

每当它落在一个键上(包括骑士的初始位置),都会拨出键所对应的数字,总共按下 N 位数字。

你能用这种方式拨出多少个不同的号码?

因为答案可能很大,所以输出答案模 10^9 + 7。

题目链接:https://leetcode.com/problems/knight-dialer/

Difficulty: medium

阅读全文 »

934.Shortest Bridge(最短的桥)

发表于 2018-11-06 | 更新于: 2018-11-07 | 分类于 leetcode

Description

In a given 2D binary array A, there are two islands. (An island is a 4-directionally connected group of 1s not connected to any other 1s.)

Now, we may change 0s to 1s so as to connect the two islands together to form 1 island.

Return the smallest number of 0s that must be flipped. (It is guaranteed that the answer is at least 1.)


在给定的二维二进制数组 A 中,存在两座岛。(岛是由四面相连的 1 形成的一个最大组。)

现在,我们可以将 0 变为 1,以使两座岛连接起来,变成一座岛。

返回必须翻转的 0 的最小数目。(可以保证答案至少是 1。)

题目链接:https://leetcode.com/problems/shortest-bridge/

Difficulty: medium

阅读全文 »

933.Number of Recent Calls(最近的请求次数)

发表于 2018-11-06 | 更新于: 2018-11-06 | 分类于 leetcode

Description

Write a class RecentCounter to count recent requests.

It has only one method: ping(int t), where t represents some time in milliseconds.

Return the number of pings that have been made from 3000 milliseconds ago until now.

Any ping with time in [t - 3000, t] will count, including the current ping.

It is guaranteed that every call to ping uses a strictly larger value of t than before.


写一个 RecentCounter 类来计算最近的请求。

它只有一个方法:ping(int t),其中 t 代表以毫秒为单位的某个时间。

返回从 3000 毫秒前到现在的 ping 数。

任何处于 [t - 3000, t] 时间范围之内的 ping 都将会被计算在内,包括当前(指 t 时刻)的 ping。

保证每次对 ping 的调用都使用比之前更大的 t 值。

题目链接:https://leetcode.com/problems/number-of-recent-calls/

Difficulty: easy

阅读全文 »

932.Beautiful Array(漂亮数组)

发表于 2018-10-28 | 更新于: 2018-11-07 | 分类于 leetcode

Description

For some fixed N, an array A is beautiful if it is a permutation of the integers 1, 2, …, N, such that:

For every i < j, there is no k with i < k < j such that A[k] * 2 = A[i] + A[j].

Given N, return any beautiful array A. (It is guaranteed that one exists.)


对于某些固定的 N,如果数组 A 是整数 1, 2, …, N 组成的排列,使得:

对于每个 i < j,都不存在 k 满足 i < k < j 使得 A[k] * 2 = A[i] + A[j]。

那么数组 A 是漂亮数组。

给定 N,返回任意漂亮数组 A(保证存在一个)。

题目链接:https://leetcode.com/problems/beautiful-array/

Difficulty: medium

阅读全文 »

931.Minimum Falling Path Sum(下降路径最小和)

发表于 2018-10-28 | 更新于: 2018-11-07 | 分类于 leetcode

Description

Given a square array of integers A, we want the minimum sum of a falling path through A.

A falling path starts at any element in the first row, and chooses one element from each row. The next row’s choice must be in a column that is different from the previous row’s column by at most one.


给定一个方形整数数组 A,我们想要得到通过 A 的下降路径的最小和。

下降路径可以从第一行中的任何元素开始,并从每一行中选择一个元素。在下一行选择的元素和当前行所选元素最多相隔一列。

题目链接:https://leetcode.com/problems/minimum-falling-path-sum/

Difficulty: medium

阅读全文 »

930.Binary Subarrays With Sum(和相同的二元子数组)

发表于 2018-10-28 | 更新于: 2018-11-07 | 分类于 leetcode

Description

In an array A of 0s and 1s, how many non-empty subarrays have sum S?


在由若干 0 和 1 组成的数组 A 中,有多少个和为 S 的非空子数组。

题目链接:https://leetcode.com/problems/binary-subarrays-with-sum/

Difficulty: medium

阅读全文 »
1…789…21
yunxiang wang

yunxiang wang

记录点点

202 日志
4 分类
41 标签
GitHub E-Mail
© 2016 — 2020 yunxiang wang