Skip to content

Commit e5be45c

Browse files
committed
feat: add solutions to lc problem: No.2727
No.2727.Is Object Empty
1 parent 89e7a96 commit e5be45c

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

solution/2700-2799/2727.Is Object Empty/README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,25 @@
5454

5555
<!-- 这里可写通用的实现逻辑 -->
5656

57+
**方法一:遍历**
58+
59+
我们可以遍历对象或数组,如果遍历到了第一个元素,就返回 `false`,否则返回 `true`
60+
61+
时间复杂度 $O(1)$,空间复杂度 $O(1)$。
62+
5763
<!-- tabs:start -->
5864

5965
### **TypeScript**
6066

6167
<!-- 这里可写当前语言的特殊实现逻辑 -->
6268

6369
```ts
64-
70+
function isEmpty(obj: Record<string, any> | any[]): boolean {
71+
for (const x in obj) {
72+
return false;
73+
}
74+
return true;
75+
}
6576
```
6677

6778
<!-- tabs:end -->

solution/2700-2799/2727.Is Object Empty/README_EN.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@
5555
### **TypeScript**
5656

5757
```ts
58-
58+
function isEmpty(obj: Record<string, any> | any[]): boolean {
59+
for (const x in obj) {
60+
return false;
61+
}
62+
return true;
63+
}
5964
```
6065

6166
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function isEmpty(obj: Record<string, any> | any[]): boolean {
2+
for (const x in obj) {
3+
return false;
4+
}
5+
return true;
6+
}

0 commit comments

Comments
 (0)