mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
44 lines
1.2 KiB
HTML
44 lines
1.2 KiB
HTML
<p>Given an object or an array, return if it is empty.</p>
|
|
|
|
<ul>
|
|
<li>An empty object contains no key-value pairs.</li>
|
|
<li>An empty array contains no elements.</li>
|
|
</ul>
|
|
|
|
<p>You may assume the object or array is the output of <code>JSON.parse</code>.</p>
|
|
|
|
<p> </p>
|
|
<p><strong class="example">Example 1:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> obj = {"x": 5, "y": 42}
|
|
<strong>Output:</strong> false
|
|
<strong>Explanation:</strong> The object has 2 key-value pairs so it is not empty.
|
|
</pre>
|
|
|
|
<p><strong class="example">Example 2:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> obj = {}
|
|
<strong>Output:</strong> true
|
|
<strong>Explanation:</strong> The object doesn't have any key-value pairs so it is empty.
|
|
</pre>
|
|
|
|
<p><strong class="example">Example 3:</strong></p>
|
|
|
|
<pre>
|
|
<strong>Input:</strong> obj = [null, false, 0]
|
|
<strong>Output:</strong> false
|
|
<strong>Explanation:</strong> The array has 3 elements so it is not empty.
|
|
</pre>
|
|
|
|
<p> </p>
|
|
<p><strong>Constraints:</strong></p>
|
|
|
|
<ul>
|
|
<li><code>obj</code> is a valid JSON object or array</li>
|
|
<li><code>2 <= JSON.stringify(obj).length <= 10<sup>5</sup></code></li>
|
|
</ul>
|
|
|
|
<p> </p>
|
|
<strong>Can you solve it in O(1) time?</strong> |