LeetCode 2727: Is Object Empty Solution

Master LeetCode problem 2727 (Is Object Empty), a easy challenge, with our optimized solutions in Java, C++, and Python. Explore detailed explanations, test your code in our interactive editor, and prepare for coding interviews.

2727. Is Object Empty

Easy

Problem Explanation

Explanation:

To determine if an object or an array is empty, we can simply check if the length of the object or array is zero. For objects, we can check the number of keys it has, and for arrays, we can check the number of elements it contains. If the length is zero, then the object or array is considered empty.

  • Time Complexity: O(1)
  • Space Complexity: O(1)

:

Solution Code

public boolean isObjectEmpty(Object obj) {
    if (obj instanceof Map) {
        return ((Map<?, ?>) obj).isEmpty();
    } else if (obj instanceof List) {
        return ((List<?>) obj).isEmpty();
    }
    return true;
}

Try It Yourself

Loading code editor...

Frequently Asked Questions

How to solve LeetCode 2727 (Is Object Empty)?

This page provides optimized solutions for LeetCode problem 2727 (Is Object Empty) in Java, C++, and Python, along with a detailed explanation and an interactive code editor to test your code.

What is the time complexity of LeetCode 2727 (Is Object Empty)?

The time complexity for LeetCode 2727 (Is Object Empty) varies by solution. Check the detailed explanation section for specific complexities in Java, C++, and Python implementations.

Can I run code for LeetCode 2727 on DevExCode?

Yes, DevExCode provides an interactive code editor where you can write, test, and run your code for LeetCode 2727 in Java, C++, or Python.

Back to LeetCode Solutions