File tree 3 files changed +24
-2
lines changed
solution/2700-2799/2727.Is Object Empty
3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change 54
54
55
55
<!-- 这里可写通用的实现逻辑 -->
56
56
57
+ ** 方法一:遍历**
58
+
59
+ 我们可以遍历对象或数组,如果遍历到了第一个元素,就返回 ` false ` ,否则返回 ` true ` 。
60
+
61
+ 时间复杂度 $O(1)$,空间复杂度 $O(1)$。
62
+
57
63
<!-- tabs:start -->
58
64
59
65
### ** TypeScript**
60
66
61
67
<!-- 这里可写当前语言的特殊实现逻辑 -->
62
68
63
69
``` 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
+ }
65
76
```
66
77
67
78
<!-- tabs:end -->
Original file line number Diff line number Diff line change 55
55
### ** TypeScript**
56
56
57
57
``` 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
+ }
59
64
```
60
65
61
66
<!-- tabs:end -->
Original file line number Diff line number Diff line change
1
+ function isEmpty ( obj : Record < string , any > | any [ ] ) : boolean {
2
+ for ( const x in obj ) {
3
+ return false ;
4
+ }
5
+ return true ;
6
+ }
You can’t perform that action at this time.
0 commit comments