代码拉取完成,页面将自动刷新
同步操作将从 小墨/力扣题库(完整版) 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
<p>Write a function that converts an array of objects <code>arr</code> into a matrix <code>m</code>.</p>
<p><code>arr</code> is an array of objects or arrays. Each item in the array can be deeply nested with child arrays and child objects. It can also contain numbers, strings, booleans, and null values.</p>
<p>The first row <code>m</code> should be the column names. If there is no nesting, the column names are the unique keys within the objects. If there is nesting, the column names are the respective paths in the object separated by <code>"."</code>.</p>
<p>Each of the remaining rows corresponds to an object in <code>arr</code>. Each value in the matrix corresponds to a value in an object. If a given object doesn't contain a value for a given column, the cell should contain an empty string <code>""</code>.</p>
<p>The colums in the matrix should be in <strong>lexographically ascending</strong> order.</p>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre>
<strong>Input:</strong>
arr = [
{"b": 1, "a": 2},
{"b": 3, "a": 4}
]
<strong>Output:</strong>
[
["a", "b"],
[2, 1],
[4, 3]
]
<strong>Explanation:</strong>
There are two unique column names in the two objects: "a" and "b".
"a" corresponds with [2, 4].
"b" coresponds with [1, 3].
</pre>
<p><strong class="example">Example 2:</strong></p>
<pre>
<strong>Input:</strong>
arr = [
{"a": 1, "b": 2},
{"c": 3, "d": 4},
{}
]
<strong>Output:</strong>
[
["a", "b", "c", "d"],
[1, 2, "", ""],
["", "", 3, 4],
["", "", "", ""]
]
<strong>Explanation:</strong>
There are 4 unique column names: "a", "b", "c", "d".
The first object has values associated with "a" and "b".
The second object has values associated with "c" and "d".
The third object has no keys, so it is just a row of empty strings.
</pre>
<p><strong class="example">Example 3:</strong></p>
<pre>
<strong>Input:</strong>
arr = [
{"a": {"b": 1, "c": 2}},
{"a": {"b": 3, "d": 4}}
]
<strong>Output:</strong>
[
["a.b", "a.c", "a.d"],
[1, 2, ""],
[3, "", 4]
]
<strong>Explanation:</strong>
In this example, the objects are nested. The keys represent the full path to each value separated by periods.
There are three paths: "a.b", "a.c", "a.d".
</pre>
<p><strong class="example">Example 4:</strong></p>
<pre>
<strong>Input:</strong>
arr = [
[{"a": null}],
[{"b": true}],
[{"c": "x"}]
]
<strong>Output:</strong>
[
["0.a", "0.b", "0.c"],
[null, "", ""],
["", true, ""],
["", "", "x"]
]
<strong>Explanation:</strong>
Arrays are also considered objects with their keys being their indices.
Each array has one element so the keys are "0.a", "0.b", and "0.c".
</pre>
<p><strong class="example">Example 5:</strong></p>
<pre>
<strong>Input:</strong>
arr = [
{},
{},
{},
]
<strong>Output:</strong>
[
[],
[],
[],
[]
]
<strong>Explanation:</strong>
There are no keys so every row is an empty array.</pre>
<p> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= arr.length <= 1000</code></li>
<li><code>unique keys <= 1000</code></li>
</ul>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。