最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

LeetCode 2283. Check if Number Has Equal Digit Count and Digit V

2023-03-21 15:24 作者:您是打尖兒還是住店呢  | 我要投稿

You are given a?0-indexed?string?num?of length?n?consisting of digits.

Return?true?if for?every?index?i?in the range?0 <= i < n, the digit?i?occurs?num[i]?times in?num, otherwise return?false.

?

Example 1:

Input: num = "1210"

Output: true

Explanation:num[0] = '1'. The digit 0 occurs once in num. num[1] = '2'. The digit 1 occurs twice in num. num[2] = '1'. The digit 2 occurs once in num. num[3] = '0'. The digit 3 occurs zero times in num. The condition holds true for every index in "1210", so return true.

Example 2:

Input: num = "030"

Output: false

Explanation:num[0] = '0'. The digit 0 should occur zero times, but actually occurs twice in num. num[1] = '3'. The digit 1 should occur three times, but actually occurs zero times in num. num[2] = '0'. The digit 2 occurs zero times in num. The indices 0 and 1 both violate the condition, so return false.

?

Constraints:

  • n == num.length

  • 1 <= n <= 10

  • num?consists of digits.

  • 把字符串中的每個數(shù)字都放到map中,然后遍歷map中的數(shù)字跟值去判斷是否是一樣的,如果不一樣則返回flag。

  • 簡單的題目,但是通過的空間跟時間復(fù)雜度都是不好的。。

Runtime:?13 ms, faster than?6.62%?of?Java?online submissions for?Check if Number Has Equal Digit Count and Digit Value.

Memory Usage:?42.7 MB, less than?6.74%?of?Java?online submissions for?Check if Number Has Equal Digit Count and Digit Value.


LeetCode 2283. Check if Number Has Equal Digit Count and Digit V的評論 (共 條)

分享到微博請遵守國家法律
罗源县| 渝中区| 洛隆县| 大新县| 海晏县| 连江县| 平昌县| 长乐市| 新河县| 驻马店市| 原阳县| 旌德县| 南木林县| 修武县| 靖州| 土默特左旗| 普定县| 巴中市| 盘锦市| 驻马店市| 奉节县| 彰武县| 连江县| 分宜县| 黑水县| 晋城| 全南县| 巴塘县| 榆社县| 万荣县| 沙河市| 鄱阳县| 新津县| 叙永县| 平武县| 德江县| 江油市| 恩平市| 个旧市| 岳普湖县| 新安县|