mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
60 lines
6.6 KiB
JSON
60 lines
6.6 KiB
JSON
{
|
|
"data": {
|
|
"question": {
|
|
"questionId": "2735",
|
|
"questionFrontendId": "2628",
|
|
"boundTopicId": null,
|
|
"title": "JSON Deep Equal",
|
|
"titleSlug": "json-deep-equal",
|
|
"content": "<p>Given two objects <code>o1</code> and <code>o2</code>, check if they are <strong>deeply equal</strong>.</p>\n\n<p>For two objects to be <strong>deeply equal</strong>, they must contain the same keys, and the associated values must also be <strong>deeply equal</strong>. Two objects are also considered <strong>deeply equal</strong> if they pass the <code>===</code> equality check.</p>\n\n<p>You may assume both objects are the output of <code>JSON.parse</code>. In other words, they are valid JSON.</p>\n\n<p>Please solve it without using lodash's <code>_.isEqual()</code> function.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> o1 = {"x":1,"y":2}, o2 = {"x":1,"y":2}\n<strong>Output:</strong> true\n<strong>Explanation:</strong> The keys and values match exactly.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> o1 = {"y":2,"x":1}, o2 = {"x":1,"y":2}\n<strong>Output:</strong> true\n<strong>Explanation:</strong> Although the keys are in a different order, they still match exactly.\n</pre>\n\n<p><strong class=\"example\">Example 3:</strong></p>\n\n<pre>\n<strong>Input:</strong> o1 = {"x":null,"L":[1,2,3]}, o2 = {"x":null,"L":["1","2","3"]}\n<strong>Output:</strong> false\n<strong>Explanation:</strong> The array of numbers is different from the array of strings.\n</pre>\n\n<p><strong class=\"example\">Example 4:</strong></p>\n\n<pre>\n<strong>Input:</strong> o1 = true, o2 = false\n<strong>Output:</strong> false\n<strong>Explanation:</strong> true !== false</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>1 <= JSON.stringify(o1).length <= 10<sup>5</sup></code></li>\n\t<li><code>1 <= JSON.stringify(o2).length <= 10<sup>5</sup></code></li>\n\t<li><code>maxNestingDepth <= 1000</code></li>\n</ul>\n",
|
|
"translatedTitle": null,
|
|
"translatedContent": null,
|
|
"isPaidOnly": false,
|
|
"difficulty": "Medium",
|
|
"likes": 13,
|
|
"dislikes": 1,
|
|
"isLiked": null,
|
|
"similarQuestions": "[{\"title\": \"Convert Object to JSON String\", \"titleSlug\": \"convert-object-to-json-string\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Flatten Deeply Nested Array\", \"titleSlug\": \"flatten-deeply-nested-array\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]",
|
|
"exampleTestcases": "{\"x\":1,\"y\":2}\n{\"x\":1,\"y\":2}\n{\"y\":2,\"x\":1}\n{\"x\":1,\"y\":2}\n{\"x\":null,\"L\":[1,2,3]}\n{\"x\":null,\"L\":[\"1\",\"2\",\"3\"]}\ntrue\nfalse",
|
|
"categoryTitle": "JavaScript",
|
|
"contributors": [],
|
|
"topicTags": [],
|
|
"companyTagStats": null,
|
|
"codeSnippets": [
|
|
{
|
|
"lang": "JavaScript",
|
|
"langSlug": "javascript",
|
|
"code": "/**\n * @param {any} o1\n * @param {any} o2\n * @return {boolean}\n */\nvar areDeeplyEqual = function(o1, o2) {\n \n};",
|
|
"__typename": "CodeSnippetNode"
|
|
},
|
|
{
|
|
"lang": "TypeScript",
|
|
"langSlug": "typescript",
|
|
"code": "function areDeeplyEqual(o1: any, o2: any): boolean {\n\n};",
|
|
"__typename": "CodeSnippetNode"
|
|
}
|
|
],
|
|
"stats": "{\"totalAccepted\": \"285\", \"totalSubmission\": \"860\", \"totalAcceptedRaw\": 285, \"totalSubmissionRaw\": 860, \"acRate\": \"33.1%\"}",
|
|
"hints": [
|
|
"You can check if a value is an array with the Array.isArray() method. You can check if a value is an object by saying typeof obj === 'object' && obj !== null. You can list the keys of an object with the Object.keys() function.",
|
|
"If two objects have different keys or two arrays have a different length, they cannot be equal.",
|
|
"You can use recursion to investigate if the values of an object or array are also deeply equal. The base case is when the values are primitives (string, number, etc), at which case the check is a trivial === check."
|
|
],
|
|
"solution": null,
|
|
"status": null,
|
|
"sampleTestCase": "{\"x\":1,\"y\":2}\n{\"x\":1,\"y\":2}",
|
|
"metaData": "{\n \"name\": \"areDeeplyEqual\",\n \"params\": [\n {\n \"type\": \"string\",\n \"name\": \"o1\"\n },\n {\n \"type\": \"string\",\n \"name\": \"o2\"\n }\n ],\n \"return\": {\n \"type\": \"boolean\"\n },\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ],\n \"manual\": true\n}",
|
|
"judgerAvailable": true,
|
|
"judgeType": "large",
|
|
"mysqlSchemas": [],
|
|
"enableRunCode": true,
|
|
"enableTestMode": false,
|
|
"enableDebugger": false,
|
|
"envInfo": "{\"javascript\": [\"JavaScript\", \"<p><code>Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES6 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\\r\\n\\r\\n<p>For Priority Queue / Queue data structures, you may use 5.3.0 version of <a href=\\\"https://github.com/datastructures-js/priority-queue/tree/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\">datastructures-js/priority-queue</a> and 4.2.1 version of <a href=\\\"https://github.com/datastructures-js/queue/tree/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\">datastructures-js/queue</a>.</p>\"], \"typescript\": [\"Typescript\", \"<p><code>TypeScript 4.5.4, Node.js 16.13.2</code>.</p>\\r\\n\\r\\n<p>Your code is run with <code>--harmony</code> flag, enabling <a href=\\\"http://node.green/\\\" target=\\\"_blank\\\">new ES2020 features</a>.</p>\\r\\n\\r\\n<p><a href=\\\"https://lodash.com\\\" target=\\\"_blank\\\">lodash.js</a> library is included by default.</p>\"]}",
|
|
"libraryUrl": null,
|
|
"adminUrl": null,
|
|
"challengeQuestion": null,
|
|
"__typename": "QuestionNode"
|
|
}
|
|
}
|
|
} |