mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-05 23:41:41 +08:00
update
This commit is contained in:
43
leetcode/problem/is-object-empty.html
Normal file
43
leetcode/problem/is-object-empty.html
Normal file
@@ -0,0 +1,43 @@
|
||||
<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>2 <= JSON.stringify(obj).length <= 10<sup>5</sup></code></li>
|
||||
</ul>
|
||||
|
||||
<p> </p>
|
||||
<strong>Can you solve it in O(1) time?</strong>
|
Reference in New Issue
Block a user