1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-11 02:58:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/problem (Chinese)/判断对象是否为空 [is-object-empty].html
2023-06-12 23:05:37 +08:00

45 lines
1.1 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<p>给定一个对象或数组,判断它是否为空。</p>
<ul>
<li>一个空对象不包含任何键值对。</li>
<li>一个空数组不包含任何元素。</li>
</ul>
<p>你可以假设对象或数组是通过 <code>JSON.parse</code> 解析得到的。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<b>输入:</b>obj = {"x": 5, "y": 42}
<b>输出:</b>false
<b>解释:</b>The object has 2 key-value pairs so it is not empty.
</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<b>输入:</b>obj = {}
<b>输出:</b>true
<b>解释:</b>The object doesn't have any key-value pairs so it is empty.
</pre>
<p><strong class="example">示例 3</strong></p>
<pre>
<b>输入:</b>obj = [null, false, 0]
<b>输出:</b>false
<b>解释:</b>The array has 3 elements so it is not empty.
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li>&nbsp;<code>2 &lt;= JSON.stringify(obj).length &lt;= 10<sup>5</sup></code></li>
</ul>
<p>&nbsp;</p>
<strong>你可以在 O(1) 时间复杂度内解决这个问题吗?</strong>