Redtongue

人生苦短,我用Python


  • 首页

  • 归档

  • 分类

  • 标签

  • 关于

  • 搜索

920.Number of Music Playlists

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

Description

Your music player contains N different songs and she wants to listen to L (not necessarily different) songs during your trip. You create a playlist so that:

  • Every song is played at least once
  • A song can only be played again only if K other songs have been played

Return the number of possible playlists. As the answer can be very large, return it modulo 10^9 + 7.

题目链接:https://leetcode.com/problems/number-of-music-playlists/

Difficulty: hard

阅读全文 »

919.Complete Binary Tree Inserter

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

Description

A complete binary tree is a binary tree in which every level, except possibly the last, is completely filled, and all nodes are as far left as possible.

Write a data structure CBTInserter that is initialized with a complete binary tree and supports the following operations:

  • CBTInserter(TreeNode root) initializes the data structure on a given tree with head node root;
  • CBTInserter.insert(int v) will insert a TreeNode into the tree with value node.val = v so that the tree remains complete, and returns the value of the parent of the inserted TreeNode;
  • CBTInserter.get_root() will return the head node of the tree.

题目链接:https://leetcode.com/problems/complete-binary-tree-inserter/

Difficulty: medium

阅读全文 »

918.Maximum Sum Circular Subarray

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

Description

Given a circular array C of integers represented by A, find the maximum possible sum of a non-empty subarray of C.

Here, a circular array means the end of the array connects to the beginning of the array. (Formally, C[i] = A[i] when 0 <= i < A.length, and C[i+A.length] = C[i] when i >= 0.)

Also, a subarray may only include each element of the fixed buffer A at most once. (Formally, for a subarray C[i], C[i+1], …, C[j], there does not exist i <= k1, k2 <= j with k1 % A.length = k2 % A.length.)

题目链接:https://leetcode.com/problems/maximum-sum-circular-subarray/

Difficulty: medium

阅读全文 »

917.Reverse Only Letters

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

Description

Given a string S, return the “reversed” string where all characters that are not a letter stay in the same place, and all letters reverse their positions.

题目链接:https://leetcode.com/problems/reverse-only-letters/

Difficulty: easy

阅读全文 »

916.Word Subsets

发表于 2018-10-01 | 更新于: 2018-10-03 | 分类于 leetcode

Description

We are given two arrays A and B of words. Each word is a string of lowercase letters.

Now, say that word b is a subset of word a if every letter in b occurs in a, including multiplicity. For example, “wrr” is a subset of “warrior”, but is not a subset of “world”.

Now say a word a from A is universal if for every b in B, b is a subset of a.

Return a list of all universal words in A. You can return the words in any order.

题目链接:https://leetcode.com/problems/word-subsets/description/

Difficulty: hard

阅读全文 »

915.Partition Array into Disjoint Intervals

发表于 2018-10-01 | 更新于: 2018-10-03 | 分类于 leetcode

Description

Given an array A, partition it into two (contiguous) subarrays left and right so that:

  • Every element in left is less than or equal to every element in right.
  • left and right are non-empty.
  • left has the smallest possible size.

Return the length of left after such a partitioning. It is guaranteed that such a partitioning exists.

题目链接:https://leetcode.com/problems/partition-array-into-disjoint-intervals/description/

Difficulty: medium

阅读全文 »

914.X of a Kind in a Deck of Cards

发表于 2018-10-01 | 更新于: 2018-10-03 | 分类于 leetcode

Description

In a deck of cards, each card has an integer written on it.

Return true if and only if you can choose X >= 2 such that it is possible to split the entire deck into 1 or more groups of cards, where:

  • Each group has exactly X cards.
  • All the cards in each group have the same integer.

题目链接:https://leetcode.com/problems/x-of-a-kind-in-a-deck-of-cards/description/

Difficulty: easy

阅读全文 »

913.Cat and Mouse

发表于 2018-10-01 | 更新于: 2018-10-03 | 分类于 leetcode

Description

A game on an undirected graph is played by two players, Mouse and Cat, who alternate turns.

The graph is given as follows: graph[a] is a list of all nodes b such that ab is an edge of the graph.

Mouse starts at node 1 and goes first, Cat starts at node 2 and goes second, and there is a Hole at node 0.

During each player’s turn, they must travel along one edge of the graph that meets where they are. For example, if the Mouse is at node 1, it must travel to any node in graph[1].

Additionally, it is not allowed for the Cat to travel to the Hole (node 0.)

Then, the game can end in 3 ways:

  • If ever the Cat occupies the same node as the Mouse, the Cat wins.
  • If ever the Mouse reaches the Hole, the Mouse wins.
  • If ever a position is repeated (ie. the players are in the same position as a previous turn, and it is the same player’s turn to move), the game is a draw.

Given a graph, and assuming both players play optimally, return 1 if the game is won by Mouse, 2 if the game is won by Cat, and 0 if the game is a draw.

题目链接:https://leetcode.com/problems/cat-and-mouse/description/

Difficulty: hard

阅读全文 »

[nowcoder66]机器人的运动范围

发表于 2018-09-22 | 更新于: 2018-11-13 | 分类于 nowcoder

题目描述

地上有一个m行和n列的方格。一个机器人从坐标0,0的格子开始移动,每一次只能向左,右,上,下四个方向移动一格,但是不能进入行坐标和列坐标的数位之和大于k的格子。 例如,当k为18时,机器人能够进入方格(35,37),因为3+5+3+7 = 18。但是,它不能进入方格(35,38),因为3+5+3+8 = 19。请问该机器人能够达到多少个格子?

题目链接: https://www.nowcoder.com/practice/6e5207314b5241fb83f2329e89fdecc8

阅读全文 »

[nowcoder65]矩阵中的路径

发表于 2018-09-22 | 更新于: 2018-11-13 | 分类于 nowcoder

题目描述

请设计一个函数,用来判断在一个矩阵中是否存在一条包含某字符串所有字符的路径。路径可以从矩阵中的任意一个格子开始,每一步可以在矩阵中向左,向右,向上,向下移动一个格子。如果一条路径经过了矩阵中的某一个格子,则之后不能再次进入这个格子。 例如 a b c e s f c s a d e e 这样的3 X 4 矩阵中包含一条字符串”bcced”的路径,但是矩阵中不包含”abcb”路径,因为字符串的第一个字符b占据了矩阵中的第一行第二个格子之后,路径不能再次进入该格子。

题目链接: https://www.nowcoder.com/practice/c61c6999eecb4b8f88a98f66b273a3cc

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

yunxiang wang

记录点点

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