Category: LeetCode

2022. Convert 1D Array Into 2D Array

题目 You are given a 0-indexed 1-dimensional (1D) integer array original, and two integers, m and n. You are tasked with creating a 2-dimensional (2D) array with m rows and n columns using all the elements from original. The elements from indices 0 to n – 1 (inclusive) of original should form the first row […]

507. Perfect Number

题目 A perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. A divisor of an integer x is an integer that can divide x evenly. Given an integer n, return true if n is a perfect number, otherwise return false. Example 1: Input: num […]

846. Hand of Straights

题目 Alice has some number of cards and she wants to rearrange the cards into groups so that each group is of size groupSize, and consists of groupSize consecutive cards. Given an integer array hand where hand[i] is the value written on the ith card and an integer groupSize, return true if she can rearrange […]

1609. Even Odd Tree

题目 A binary tree is named Even-Odd if it meets the following conditions: The root of the binary tree is at level index 0, its children are at level index 1, their children are at level index 2, etc.For every even-indexed level, all nodes at the level have odd integer values in strictly increasing order […]

686. 重复叠加字符串匹配【中等】

题目 给定两个字符串 a 和 b,寻找重复叠加字符串 a 的最小次数,使得字符串 b 成为叠加后的字符串 a 的子串,如果不存在则返回 -1。 注意:字符串 “abc” 重复叠加 0 次是 “”,重复叠加 1 次是 “abc”,重复叠加 2 次是 “abcabc”。 示例 1: 输入:a = “abcd”, b = “cdabcdab”输出:3解释:a 重复叠加三遍后为 “abcdabcdabcd”, 此时 b 是其子串。示例 2: 输入:a = “a”, b = “aa”输出:2示例 3: 输入:a = “a”, b = “a”输出:1示例 4: 输入:a = “abc”, b = “wxyz”输出:-1  提示: […]

1154. 一年中的第几天 【简单】

给你一个字符串 date ,按 YYYY-MM-DD 格式表示一个 现行公元纪年法 日期。请你计算并返回该日期是当年的第几天。 通常情况下,我们认为 1 月 1 日是每年的第 1 天,1 月 2 日是每年的第 2 天,依此类推。每个月的天数与现行公元纪年法(格里高利历)一致。 示例 1: 输入:date = “2019-01-09”输出:9示例 2: 输入:date = “2019-02-10”输出:41示例 3: 输入:date = “2003-03-01”输出:60示例 4: 输入:date = “2004-03-01”输出:61  提示: date.length == 10date[4] == date[7] == ‘-‘,其他的 date[i] 都是数字date 表示的范围从 1900 年 1 月 1 日至 2019 年 12 月 31 […]