diff --git a/leetcode-cn/originData/[no content]array-of-objects-to-matrix.json b/leetcode-cn/originData/[no content]array-of-objects-to-matrix.json new file mode 100644 index 00000000..82785ad8 --- /dev/null +++ b/leetcode-cn/originData/[no content]array-of-objects-to-matrix.json @@ -0,0 +1,50 @@ +{ + "data": { + "question": { + "questionId": "2769", + "questionFrontendId": "2675", + "categoryTitle": "JavaScript", + "boundTopicId": 2267107, + "title": "Array of Objects to Matrix", + "titleSlug": "array-of-objects-to-matrix", + "content": null, + "translatedTitle": "将对象数组转换为矩阵", + "translatedContent": null, + "isPaidOnly": true, + "difficulty": "Hard", + "likes": 2, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": null, + "topicTags": [], + "companyTagStats": null, + "codeSnippets": null, + "stats": "{\"totalAccepted\": \"751\", \"totalSubmission\": \"1.3K\", \"totalAcceptedRaw\": 751, \"totalSubmissionRaw\": 1314, \"acRate\": \"57.2%\"}", + "hints": [ + "How could you split the problem up into sub-problems?", + "1.) Write a function that converts a single object into a dictionary that maps the path name to values. You can solve this recursively by keeping track of current path list.", + "2.) Write a function that converts a list of dictionaries into a matrix. Start by creating a list of all possible paths in any of the dictionaries. This will represent the columns." + ], + "solution": null, + "status": null, + "sampleTestCase": "[{\"b\":1,\"a\":2},{\"b\":3,\"a\":4}]", + "metaData": "{\n \"name\": \"jsonToMatrix\",\n \"params\": [\n {\n \"name\": \"arr\",\n \"type\": \"string\"\n }\n ],\n \"return\": {\n \"type\": \"string\"\n },\n \"languages\": [\n \"typescript\",\n \"javascript\"\n ],\n \"manual\": true\n}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [], + "enableRunCode": true, + "envInfo": "{\"javascript\":[\"JavaScript\",\"

\\u7248\\u672c\\uff1aNode.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n

\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a --harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f \\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n

lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n

\\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"

TypeScript 5.1.6<\\/p>\\r\\n\\r\\n

Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/p>\\r\\n\\r\\n

lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n

\\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "[{\"b\":1,\"a\":2},{\"b\":3,\"a\":4}]\n[{\"a\":1,\"b\":2},{\"c\":3,\"d\":4},{}]\n[{\"a\":{\"b\":1,\"c\":2}},{\"a\":{\"b\":3,\"d\":4}}]\n[[{\"a\":null}],[{\"b\":true}],[{\"c\":\"x\"}]]\n[{},{},{}]", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/[no content]convert-object-to-json-string.json b/leetcode-cn/originData/[no content]convert-object-to-json-string.json new file mode 100644 index 00000000..60b06b8a --- /dev/null +++ b/leetcode-cn/originData/[no content]convert-object-to-json-string.json @@ -0,0 +1,50 @@ +{ + "data": { + "question": { + "questionId": "2745", + "questionFrontendId": "2633", + "categoryTitle": "JavaScript", + "boundTopicId": 2222275, + "title": "Convert Object to JSON String", + "titleSlug": "convert-object-to-json-string", + "content": null, + "translatedTitle": "将对象转换为 JSON 字符串", + "translatedContent": null, + "isPaidOnly": true, + "difficulty": "Medium", + "likes": 3, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": null, + "topicTags": [], + "companyTagStats": null, + "codeSnippets": null, + "stats": "{\"totalAccepted\": \"1.3K\", \"totalSubmission\": \"2.2K\", \"totalAcceptedRaw\": 1300, \"totalSubmissionRaw\": 2202, \"acRate\": \"59.0%\"}", + "hints": [ + "Consider the 4 possibilities. The object could be an array, an object, a string, or another type.", + "Think about the problem recursively. If you know how to convert any sub-data into a string, how could you use it to convert the entire data into a string?", + "If the data is a string, it's just the value surrounded by double quotes. If the data is another type, its just String(data). If the data is an array, it's the recursively stringified value of each item separated by commas. If the data is an object, it's a series of key-value pairs where each value is the recursively stringified value." + ], + "solution": null, + "status": null, + "sampleTestCase": "{\"y\":1,\"x\":2}", + "metaData": "{\n \"name\": \"jsonStringify\",\n \"params\": [\n {\n \"name\": \"object\",\n \"type\": \"string\"\n }\n ],\n \"return\": {\n \"type\": \"string\"\n },\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ],\n \"manual\": true\n}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [], + "enableRunCode": true, + "envInfo": "{\"javascript\":[\"JavaScript\",\"

\\u7248\\u672c\\uff1aNode.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n

\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a --harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f \\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n

lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n

\\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"

TypeScript 5.1.6<\\/p>\\r\\n\\r\\n

Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/p>\\r\\n\\r\\n

lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n

\\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"y\":1,\"x\":2}\n{\"a\":\"str\",\"b\":-12,\"c\":true,\"d\":null}\n{\"key\":{\"a\":1,\"b\":[{},null,\"Hello\"]}}\ntrue", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/[no content]curry.json b/leetcode-cn/originData/[no content]curry.json new file mode 100644 index 00000000..cbe016de --- /dev/null +++ b/leetcode-cn/originData/[no content]curry.json @@ -0,0 +1,49 @@ +{ + "data": { + "question": { + "questionId": "2740", + "questionFrontendId": "2632", + "categoryTitle": "JavaScript", + "boundTopicId": 2222271, + "title": "Curry", + "titleSlug": "curry", + "content": null, + "translatedTitle": "柯里化", + "translatedContent": null, + "isPaidOnly": true, + "difficulty": "Medium", + "likes": 14, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": null, + "topicTags": [], + "companyTagStats": null, + "codeSnippets": null, + "stats": "{\"totalAccepted\": \"1.9K\", \"totalSubmission\": \"2.3K\", \"totalAcceptedRaw\": 1850, \"totalSubmissionRaw\": 2255, \"acRate\": \"82.0%\"}", + "hints": [ + "You can access the count of parameters expected to passed into a function with \"fn.length\".", + "You can use recursion. If the length of params passed is equal to fn.length, you are done. Just pass those params to fn. Otherwise return a function that is includes the previous passed params plus the new params. The new function should contain a recursive call to curry()." + ], + "solution": null, + "status": null, + "sampleTestCase": "function sum(a, b, c) { return a + b + c; }\n[[1],[2],[3]]", + "metaData": "{\n \"name\": \"curry\",\n \"params\": [\n {\n \"name\": \"fn\",\n \"type\": \"string\"\n },\n {\n \"type\": \"integer[][]\",\n \"name\": \"inputs\"\n }\n ],\n \"return\": {\n \"type\": \"string\"\n },\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ],\n \"manual\": true\n}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [], + "enableRunCode": true, + "envInfo": "{\"javascript\":[\"JavaScript\",\"

\\u7248\\u672c\\uff1aNode.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n

\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a --harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f \\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n

lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n

\\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"

TypeScript 5.1.6<\\/p>\\r\\n\\r\\n

Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/p>\\r\\n\\r\\n

lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n

\\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "function sum(a, b, c) { return a + b + c; }\n[[1],[2],[3]]\nfunction sum(a, b, c) { return a + b + c; }\n[[1,2],[3]]\nfunction sum(a, b, c) { return a + b + c; }\n[[],[],[1,2,3]]\nfunction life() { return 42; }\n[[]]", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/[no content]differences-between-two-objects.json b/leetcode-cn/originData/[no content]differences-between-two-objects.json new file mode 100644 index 00000000..960c95ce --- /dev/null +++ b/leetcode-cn/originData/[no content]differences-between-two-objects.json @@ -0,0 +1,50 @@ +{ + "data": { + "question": { + "questionId": "2774", + "questionFrontendId": "2700", + "categoryTitle": "JavaScript", + "boundTopicId": 2278876, + "title": "Differences Between Two Objects", + "titleSlug": "differences-between-two-objects", + "content": null, + "translatedTitle": "两个对象之间的差异", + "translatedContent": null, + "isPaidOnly": true, + "difficulty": "Medium", + "likes": 2, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": null, + "topicTags": [], + "companyTagStats": null, + "codeSnippets": null, + "stats": "{\"totalAccepted\": \"614\", \"totalSubmission\": \"1.1K\", \"totalAcceptedRaw\": 614, \"totalSubmissionRaw\": 1067, \"acRate\": \"57.5%\"}", + "hints": [ + "Find the intersection of the keys/indices on the two arrays/objects.", + "Analyze the data structure recursively.", + "For each key in the intersection, omit if there are no differences in the leaves. Otherwise return the difference." + ], + "solution": null, + "status": null, + "sampleTestCase": "{}\n{\"a\": 1, \"b\": 2}", + "metaData": "{\n \"name\": \"objDiff\",\n \"params\": [\n {\n \"name\": \"obj1\",\n \"type\": \"string\"\n },\n {\n \"type\": \"string\",\n \"name\": \"obj2\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n },\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ],\n \"manual\": true\n}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [], + "enableRunCode": true, + "envInfo": "{\"javascript\":[\"JavaScript\",\"

\\u7248\\u672c\\uff1aNode.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n

\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a --harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f \\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n

lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n

\\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"

TypeScript 5.1.6<\\/p>\\r\\n\\r\\n

Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/p>\\r\\n\\r\\n

lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n

\\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{}\n{\"a\": 1, \"b\": 2}\n{\"a\": 1, \"v\": 3, \"x\": [], \"z\": {\"a\": null}}\n{\"a\": 2, \"v\": 4, \"x\": [], \"z\": {\"a\": 2}}\n{\"a\": 5, \"v\": 6, \"z\": [1,2,4, [2,5,7]]}\n{\"a\": 5, \"v\": 7, \"z\": [1,2,3, [1]]}\n{\"a\":{\"b\":1}}\n{\"a\":[5]}\n{\"a\": [1, 2, {}],\"b\": false}\n{\"b\": false, \"a\": [1, 2, {}]}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/[no content]json-deep-equal.json b/leetcode-cn/originData/[no content]json-deep-equal.json new file mode 100644 index 00000000..c46eb611 --- /dev/null +++ b/leetcode-cn/originData/[no content]json-deep-equal.json @@ -0,0 +1,50 @@ +{ + "data": { + "question": { + "questionId": "2735", + "questionFrontendId": "2628", + "categoryTitle": "JavaScript", + "boundTopicId": 2222277, + "title": "JSON Deep Equal", + "titleSlug": "json-deep-equal", + "content": null, + "translatedTitle": "完全相等的 JSON 字符串", + "translatedContent": null, + "isPaidOnly": true, + "difficulty": "Medium", + "likes": 8, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": null, + "topicTags": [], + "companyTagStats": null, + "codeSnippets": null, + "stats": "{\"totalAccepted\": \"1.6K\", \"totalSubmission\": \"4.8K\", \"totalAcceptedRaw\": 1589, \"totalSubmissionRaw\": 4799, \"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, + "envInfo": "{\"javascript\":[\"JavaScript\",\"

\\u7248\\u672c\\uff1aNode.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n

\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a --harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f \\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n

lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n

\\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"

TypeScript 5.1.6<\\/p>\\r\\n\\r\\n

Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/p>\\r\\n\\r\\n

lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n

\\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "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", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/[no content]promise-pool.json b/leetcode-cn/originData/[no content]promise-pool.json new file mode 100644 index 00000000..2d36b894 --- /dev/null +++ b/leetcode-cn/originData/[no content]promise-pool.json @@ -0,0 +1,49 @@ +{ + "data": { + "question": { + "questionId": "2750", + "questionFrontendId": "2636", + "categoryTitle": "JavaScript", + "boundTopicId": 2222268, + "title": "Promise Pool", + "titleSlug": "promise-pool", + "content": null, + "translatedTitle": "Promise 对象池", + "translatedContent": null, + "isPaidOnly": true, + "difficulty": "Medium", + "likes": 13, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": null, + "topicTags": [], + "companyTagStats": null, + "codeSnippets": null, + "stats": "{\"totalAccepted\": \"1.3K\", \"totalSubmission\": \"2K\", \"totalAcceptedRaw\": 1294, \"totalSubmissionRaw\": 2045, \"acRate\": \"63.3%\"}", + "hints": [ + "Initially execute all the functions until the queue fills up.", + "Every time a function resolves, add a new promise to the queue if possible." + ], + "solution": null, + "status": null, + "sampleTestCase": "[() => new Promise(res => setTimeout(res, 300)), () => new Promise(res => setTimeout(res, 400)), () => new Promise(res => setTimeout(res, 200))]\n2", + "metaData": "{\n \"name\": \"promisePool\",\n \"params\": [\n {\n \"name\": \"getFunctions\",\n \"type\": \"string\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"n\"\n }\n ],\n \"return\": {\n \"type\": \"string\"\n },\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ],\n \"manual\": true\n}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [], + "enableRunCode": true, + "envInfo": "{\"javascript\":[\"JavaScript\",\"

\\u7248\\u672c\\uff1aNode.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n

\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a --harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f \\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n

lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n

\\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"

TypeScript 5.1.6<\\/p>\\r\\n\\r\\n

Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/p>\\r\\n\\r\\n

lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n

\\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "[() => new Promise(res => setTimeout(res, 300)), () => new Promise(res => setTimeout(res, 400)), () => new Promise(res => setTimeout(res, 200))]\n2\n[() => new Promise(res => setTimeout(res, 300)), () => new Promise(res => setTimeout(res, 400)), () => new Promise(res => setTimeout(res, 200))]\n5\n[() => new Promise(res => setTimeout(res, 300)), () => new Promise(res => setTimeout(res, 400)), () => new Promise(res => setTimeout(res, 200))]\n1", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/[no content]throttle.json b/leetcode-cn/originData/[no content]throttle.json new file mode 100644 index 00000000..d5f5042e --- /dev/null +++ b/leetcode-cn/originData/[no content]throttle.json @@ -0,0 +1,50 @@ +{ + "data": { + "question": { + "questionId": "2771", + "questionFrontendId": "2676", + "categoryTitle": "JavaScript", + "boundTopicId": 2267103, + "title": "Throttle", + "titleSlug": "throttle", + "content": null, + "translatedTitle": "节流", + "translatedContent": null, + "isPaidOnly": true, + "difficulty": "Medium", + "likes": 3, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": null, + "topicTags": [], + "companyTagStats": null, + "codeSnippets": null, + "stats": "{\"totalAccepted\": \"961\", \"totalSubmission\": \"2.1K\", \"totalAcceptedRaw\": 961, \"totalSubmissionRaw\": 2134, \"acRate\": \"45.0%\"}", + "hints": [ + "Store a variable for currArguments.", + "If no timeout is in progress, immediately execute the function and create a timeout. If a timeout is in progress, set the currArguments to the new arguments.", + "When the timeout is done: if currArguments is null, do nothing. Otherwise, execute the function with currArguments and create another timeout." + ], + "solution": null, + "status": null, + "sampleTestCase": "100\n[{\"t\":20,\"inputs\":[1]}]", + "metaData": "{\n \"name\": \"throttle\",\n \"params\": [\n {\n \"name\": \"fn\",\n \"type\": \"string\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"t\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\n },\n \"languages\": [\n \"javascript\",\n \"typescript\"\n ],\n \"manual\": true\n}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [], + "enableRunCode": true, + "envInfo": "{\"javascript\":[\"JavaScript\",\"

\\u7248\\u672c\\uff1aNode.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n

\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a --harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f \\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n

lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n

\\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"

TypeScript 5.1.6<\\/p>\\r\\n\\r\\n

Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/p>\\r\\n\\r\\n

lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n

\\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "100\n[{\"t\":20,\"inputs\":[1]}]\n50\n[{\"t\":50,\"inputs\":[1]},{\"t\":75,\"inputs\":[2]}]\n70\n[{\"t\":50,\"inputs\":[1]},{\"t\":75,\"inputs\":[2]},{\"t\":90,\"inputs\":[8]},{\"t\": 140, \"inputs\":[5,7]},{\"t\": 300, \"inputs\": [9,4]}]", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/average-selling-price.json b/leetcode-cn/originData/average-selling-price.json new file mode 100644 index 00000000..e379378b --- /dev/null +++ b/leetcode-cn/originData/average-selling-price.json @@ -0,0 +1,97 @@ +{ + "data": { + "question": { + "questionId": "1390", + "questionFrontendId": "1251", + "categoryTitle": "Database", + "boundTopicId": 41811, + "title": "Average Selling Price", + "titleSlug": "average-selling-price", + "content": "

Table: Prices

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| start_date    | date    |\n| end_date      | date    |\n| price         | int     |\n+---------------+---------+\n(product_id, start_date, end_date) is the primary key (combination of columns with unique values) for this table.\nEach row of this table indicates the price of the product_id in the period from start_date to end_date.\nFor each product_id there will be no two overlapping periods. That means there will be no two intersecting periods for the same product_id.\n
\n\n

 

\n\n

Table: UnitsSold

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| purchase_date | date    |\n| units         | int     |\n+---------------+---------+\nThis table may contain duplicate rows.\nEach row of this table indicates the date, units, and product_id of each product sold. \n
\n\n

 

\n\n

Write a solution to find the average selling price for each product. average_price should be rounded to 2 decimal places.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nPrices table:\n+------------+------------+------------+--------+\n| product_id | start_date | end_date   | price  |\n+------------+------------+------------+--------+\n| 1          | 2019-02-17 | 2019-02-28 | 5      |\n| 1          | 2019-03-01 | 2019-03-22 | 20     |\n| 2          | 2019-02-01 | 2019-02-20 | 15     |\n| 2          | 2019-02-21 | 2019-03-31 | 30     |\n+------------+------------+------------+--------+\nUnitsSold table:\n+------------+---------------+-------+\n| product_id | purchase_date | units |\n+------------+---------------+-------+\n| 1          | 2019-02-25    | 100   |\n| 1          | 2019-03-01    | 15    |\n| 2          | 2019-02-10    | 200   |\n| 2          | 2019-03-22    | 30    |\n+------------+---------------+-------+\nOutput: \n+------------+---------------+\n| product_id | average_price |\n+------------+---------------+\n| 1          | 6.96          |\n| 2          | 16.96         |\n+------------+---------------+\nExplanation: \nAverage selling price = Total Price of Product / Number of products sold.\nAverage selling price for product 1 = ((100 * 5) + (15 * 20)) / 115 = 6.96\nAverage selling price for product 2 = ((200 * 15) + (30 * 30)) / 230 = 16.96\n
\n", + "translatedTitle": "平均售价", + "translatedContent": "

表:Prices

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| start_date    | date    |\n| end_date      | date    |\n| price         | int     |\n+---------------+---------+\n(product_id,start_date,end_date) 是 prices 表的主键(具有唯一值的列的组合)。\nprices 表的每一行表示的是某个产品在一段时期内的价格。\n每个产品的对应时间段是不会重叠的,这也意味着同一个产品的价格时段不会出现交叉。
\n\n

 

\n\n

表:UnitsSold

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| purchase_date | date    |\n| units         | int     |\n+---------------+---------+\n该表可能包含重复数据。\n表的每一行表示的是每种产品的出售日期,单位和产品 id。
\n\n

 

\n\n

编写解决方案以查找每种产品的平均售价。average_price 应该 四舍五入到小数点后两位

\n\n

返回结果表 无顺序要求

\n\n

结果格式如下例所示。

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nPrices table:\n+------------+------------+------------+--------+\n| product_id | start_date | end_date   | price  |\n+------------+------------+------------+--------+\n| 1          | 2019-02-17 | 2019-02-28 | 5      |\n| 1          | 2019-03-01 | 2019-03-22 | 20     |\n| 2          | 2019-02-01 | 2019-02-20 | 15     |\n| 2          | 2019-02-21 | 2019-03-31 | 30     |\n+------------+------------+------------+--------+\nUnitsSold table:\n+------------+---------------+-------+\n| product_id | purchase_date | units |\n+------------+---------------+-------+\n| 1          | 2019-02-25    | 100   |\n| 1          | 2019-03-01    | 15    |\n| 2          | 2019-02-10    | 200   |\n| 2          | 2019-03-22    | 30    |\n+------------+---------------+-------+\n输出:\n+------------+---------------+\n| product_id | average_price |\n+------------+---------------+\n| 1          | 6.96          |\n| 2          | 16.96         |\n+------------+---------------+\n解释:\n平均售价 = 产品总价 / 销售的产品数量。\n产品 1 的平均售价 = ((100 * 5)+(15 * 20) )/ 115 = 6.96\n产品 2 的平均售价 = ((200 * 15)+(30 * 30) )/ 230 = 16.96
\n", + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 110, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef average_selling_price(prices: pd.DataFrame, units_sold: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"36.8K\", \"totalSubmission\": \"64.5K\", \"totalAcceptedRaw\": 36755, \"totalSubmissionRaw\": 64499, \"acRate\": \"57.0%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Prices\":[\"product_id\",\"start_date\",\"end_date\",\"price\"],\"UnitsSold\":[\"product_id\",\"purchase_date\",\"units\"]},\"rows\":{\"Prices\":[[1,\"2019-02-17\",\"2019-02-28\",5],[1,\"2019-03-01\",\"2019-03-22\",20],[2,\"2019-02-01\",\"2019-02-20\",15],[2,\"2019-02-21\",\"2019-03-31\",30]],\"UnitsSold\":[[1,\"2019-02-25\",100],[1,\"2019-03-01\",15],[2,\"2019-02-10\",200],[2,\"2019-03-22\",30]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Prices (product_id int, start_date date, end_date date, price int)\",\"Create table If Not Exists UnitsSold (product_id int, purchase_date date, units int)\"],\"mssql\":[\"Create table Prices (product_id int, start_date date, end_date date, price int)\",\"Create table UnitsSold (product_id int, purchase_date date, units int)\"],\"oraclesql\":[\"Create table Prices (product_id int, start_date date, end_date date, price int)\",\"Create table UnitsSold (product_id int, purchase_date date, units int)\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"],\"database\":true,\"name\":\"average_selling_price\",\"pythondata\":[\"Prices = pd.DataFrame([], columns=['product_id', 'start_date', 'end_date', 'price']).astype({'product_id':'Int64', 'start_date':'datetime64[ns]', 'end_date':'datetime64[ns]', 'price':'Int64'})\",\"UnitsSold = pd.DataFrame([], columns=['product_id', 'purchase_date', 'units']).astype({'product_id':'Int64', 'purchase_date':'datetime64[ns]', 'units':'Int64'})\"],\"postgresql\":[\"\\nCreate table If Not Exists Prices (product_id int, start_date date, end_date date, price int)\\n\",\"Create table If Not Exists UnitsSold (product_id int, purchase_date date, units int)\"],\"database_schema\":{\"Prices\":{\"product_id\":\"INT\",\"start_date\":\"DATE\",\"end_date\":\"DATE\",\"price\":\"INT\"},\"UnitsSold\":{\"product_id\":\"INT\",\"purchase_date\":\"DATE\",\"units\":\"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Prices (product_id int, start_date date, end_date date, price int)", + "Create table If Not Exists UnitsSold (product_id int, purchase_date date, units int)", + "Truncate table Prices", + "insert into Prices (product_id, start_date, end_date, price) values ('1', '2019-02-17', '2019-02-28', '5')", + "insert into Prices (product_id, start_date, end_date, price) values ('1', '2019-03-01', '2019-03-22', '20')", + "insert into Prices (product_id, start_date, end_date, price) values ('2', '2019-02-01', '2019-02-20', '15')", + "insert into Prices (product_id, start_date, end_date, price) values ('2', '2019-02-21', '2019-03-31', '30')", + "Truncate table UnitsSold", + "insert into UnitsSold (product_id, purchase_date, units) values ('1', '2019-02-25', '100')", + "insert into UnitsSold (product_id, purchase_date, units) values ('1', '2019-03-01', '15')", + "insert into UnitsSold (product_id, purchase_date, units) values ('2', '2019-02-10', '200')", + "insert into UnitsSold (product_id, purchase_date, units) values ('2', '2019-03-22', '30')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Prices\":[\"product_id\",\"start_date\",\"end_date\",\"price\"],\"UnitsSold\":[\"product_id\",\"purchase_date\",\"units\"]},\"rows\":{\"Prices\":[[1,\"2019-02-17\",\"2019-02-28\",5],[1,\"2019-03-01\",\"2019-03-22\",20],[2,\"2019-02-01\",\"2019-02-20\",15],[2,\"2019-02-21\",\"2019-03-31\",30]],\"UnitsSold\":[[1,\"2019-02-25\",100],[1,\"2019-03-01\",15],[2,\"2019-02-10\",200],[2,\"2019-03-22\",30]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/average-time-of-process-per-machine.json b/leetcode-cn/originData/average-time-of-process-per-machine.json new file mode 100644 index 00000000..32419409 --- /dev/null +++ b/leetcode-cn/originData/average-time-of-process-per-machine.json @@ -0,0 +1,99 @@ +{ + "data": { + "question": { + "questionId": "1801", + "questionFrontendId": "1661", + "categoryTitle": "Database", + "boundTopicId": 491034, + "title": "Average Time of Process per Machine", + "titleSlug": "average-time-of-process-per-machine", + "content": "

Table: Activity

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| machine_id     | int     |\n| process_id     | int     |\n| activity_type  | enum    |\n| timestamp      | float   |\n+----------------+---------+\nThe table shows the user activities for a factory website.\n(machine_id, process_id, activity_type) is the primary key (combination of columns with unique values) of this table.\nmachine_id is the ID of a machine.\nprocess_id is the ID of a process running on the machine with ID machine_id.\nactivity_type is an ENUM (category) of type ('start', 'end').\ntimestamp is a float representing the current time in seconds.\n'start' means the machine starts the process at the given timestamp and 'end' means the machine ends the process at the given timestamp.\nThe 'start' timestamp will always be before the 'end' timestamp for every (machine_id, process_id) pair.
\n\n

 

\n\n

There is a factory website that has several machines each running the same number of processes. Write a solution to find the average time each machine takes to complete a process.

\n\n

The time to complete a process is the 'end' timestamp minus the 'start' timestamp. The average time is calculated by the total time to complete every process on the machine divided by the number of processes that were run.

\n\n

The resulting table should have the machine_id along with the average time as processing_time, which should be rounded to 3 decimal places.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nActivity table:\n+------------+------------+---------------+-----------+\n| machine_id | process_id | activity_type | timestamp |\n+------------+------------+---------------+-----------+\n| 0          | 0          | start         | 0.712     |\n| 0          | 0          | end           | 1.520     |\n| 0          | 1          | start         | 3.140     |\n| 0          | 1          | end           | 4.120     |\n| 1          | 0          | start         | 0.550     |\n| 1          | 0          | end           | 1.550     |\n| 1          | 1          | start         | 0.430     |\n| 1          | 1          | end           | 1.420     |\n| 2          | 0          | start         | 4.100     |\n| 2          | 0          | end           | 4.512     |\n| 2          | 1          | start         | 2.500     |\n| 2          | 1          | end           | 5.000     |\n+------------+------------+---------------+-----------+\nOutput: \n+------------+-----------------+\n| machine_id | processing_time |\n+------------+-----------------+\n| 0          | 0.894           |\n| 1          | 0.995           |\n| 2          | 1.456           |\n+------------+-----------------+\nExplanation: \nThere are 3 machines running 2 processes each.\nMachine 0's average time is ((1.520 - 0.712) + (4.120 - 3.140)) / 2 = 0.894\nMachine 1's average time is ((1.550 - 0.550) + (1.420 - 0.430)) / 2 = 0.995\nMachine 2's average time is ((4.512 - 4.100) + (5.000 - 2.500)) / 2 = 1.456\n
\n", + "translatedTitle": "每台机器的进程平均运行时间", + "translatedContent": "

表: Activity

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| machine_id     | int     |\n| process_id     | int     |\n| activity_type  | enum    |\n| timestamp      | float   |\n+----------------+---------+\n该表展示了一家工厂网站的用户活动。\n(machine_id, process_id, activity_type) 是当前表的主键(具有唯一值的列的组合)。\nmachine_id 是一台机器的ID号。\nprocess_id 是运行在各机器上的进程ID号。\nactivity_type 是枚举类型 ('start', 'end')。\ntimestamp 是浮点类型,代表当前时间(以秒为单位)。\n'start' 代表该进程在这台机器上的开始运行时间戳 , 'end' 代表该进程在这台机器上的终止运行时间戳。\n同一台机器,同一个进程都有一对开始时间戳和结束时间戳,而且开始时间戳永远在结束时间戳前面。
\n\n

 

\n\n

现在有一个工厂网站由几台机器运行,每台机器上运行着 相同数量的进程 。编写解决方案,计算每台机器各自完成一个进程任务的平均耗时。

\n\n

完成一个进程任务的时间指进程的'end' 时间戳 减去 'start' 时间戳。平均耗时通过计算每台机器上所有进程任务的总耗费时间除以机器上的总进程数量获得。

\n\n

结果表必须包含machine_id(机器ID) 和对应的 average time(平均耗时) 别名 processing_time,且四舍五入保留3位小数。

\n\n

任意顺序 返回表。

\n\n

具体参考例子如下。

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nActivity table:\n+------------+------------+---------------+-----------+\n| machine_id | process_id | activity_type | timestamp |\n+------------+------------+---------------+-----------+\n| 0          | 0          | start         | 0.712     |\n| 0          | 0          | end           | 1.520     |\n| 0          | 1          | start         | 3.140     |\n| 0          | 1          | end           | 4.120     |\n| 1          | 0          | start         | 0.550     |\n| 1          | 0          | end           | 1.550     |\n| 1          | 1          | start         | 0.430     |\n| 1          | 1          | end           | 1.420     |\n| 2          | 0          | start         | 4.100     |\n| 2          | 0          | end           | 4.512     |\n| 2          | 1          | start         | 2.500     |\n| 2          | 1          | end           | 5.000     |\n+------------+------------+---------------+-----------+\n输出:\n+------------+-----------------+\n| machine_id | processing_time |\n+------------+-----------------+\n| 0          | 0.894           |\n| 1          | 0.995           |\n| 2          | 1.456           |\n+------------+-----------------+\n解释:\n一共有3台机器,每台机器运行着两个进程.\n机器 0 的平均耗时: ((1.520 - 0.712) + (4.120 - 3.140)) / 2 = 0.894\n机器 1 的平均耗时: ((1.550 - 0.550) + (1.420 - 0.430)) / 2 = 0.995\n机器 2 的平均耗时: ((4.512 - 4.100) + (5.000 - 2.500)) / 2 = 1.456
\n", + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 110, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef get_average_time(activity: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"26K\", \"totalSubmission\": \"37.7K\", \"totalAcceptedRaw\": 25959, \"totalSubmissionRaw\": 37664, \"acRate\": \"68.9%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Activity\":[\"machine_id\",\"process_id\",\"activity_type\",\"timestamp\"]},\"rows\":{\"Activity\":[[0,0,\"start\",0.712],[0,0,\"end\",1.52],[0,1,\"start\",3.14],[0,1,\"end\",4.12],[1,0,\"start\",0.55],[1,0,\"end\",1.55],[1,1,\"start\",0.43],[1,1,\"end\",1.42],[2,0,\"start\",4.1],[2,0,\"end\",4.512],[2,1,\"start\",2.5],[2,1,\"end\",5]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Activity (machine_id int, process_id int, activity_type ENUM('start', 'end'), timestamp float)\"],\"mssql\":[\"create table Activity (machine_id int, process_id int, activity_type varchar(15) not null check(activity_type in ('start', 'end')), timestamp float)\"],\"oraclesql\":[\"create table Activity (machine_id int, process_id int, activity_type varchar(15) not null check(activity_type in ('start', 'end')), timestamp float)\"],\"database\":true,\"name\":\"get_average_time\",\"pythondata\":[\"Activity = pd.DataFrame([], columns=['machine_id', 'process_id', 'activity_type', 'timestamp']).astype({'machine_id':'Int64', 'process_id':'Int64', 'activity_type':'object', 'timestamp':'Float64'})\"],\"postgresql\":[\"Create table If Not Exists Activity (machine_id int, process_id int, activity_type VARCHAR(30) CHECK (activity_type IN ('start', 'end')), timestamp float)\\n\"],\"database_schema\":{\"Activity\":{\"machine_id\":\"INT\",\"process_id\":\"INT\",\"activity_type\":\"ENUM('start', 'end')\",\"timestamp\":\"FLOAT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Activity (machine_id int, process_id int, activity_type ENUM('start', 'end'), timestamp float)", + "Truncate table Activity", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('0', '0', 'start', '0.712')", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('0', '0', 'end', '1.52')", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('0', '1', 'start', '3.14')", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('0', '1', 'end', '4.12')", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('1', '0', 'start', '0.55')", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('1', '0', 'end', '1.55')", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('1', '1', 'start', '0.43')", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('1', '1', 'end', '1.42')", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('2', '0', 'start', '4.1')", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('2', '0', 'end', '4.512')", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('2', '1', 'start', '2.5')", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('2', '1', 'end', '5')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Activity\":[\"machine_id\",\"process_id\",\"activity_type\",\"timestamp\"]},\"rows\":{\"Activity\":[[0,0,\"start\",0.712],[0,0,\"end\",1.52],[0,1,\"start\",3.14],[0,1,\"end\",4.12],[1,0,\"start\",0.55],[1,0,\"end\",1.55],[1,1,\"start\",0.43],[1,1,\"end\",1.42],[2,0,\"start\",4.1],[2,0,\"end\",4.512],[2,1,\"start\",2.5],[2,1,\"end\",5]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/biggest-single-number.json b/leetcode-cn/originData/biggest-single-number.json new file mode 100644 index 00000000..34717e2f --- /dev/null +++ b/leetcode-cn/originData/biggest-single-number.json @@ -0,0 +1,95 @@ +{ + "data": { + "question": { + "questionId": "619", + "questionFrontendId": "619", + "categoryTitle": "Database", + "boundTopicId": 2630, + "title": "Biggest Single Number", + "titleSlug": "biggest-single-number", + "content": "

Table: MyNumbers

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| num         | int  |\n+-------------+------+\nThis table may contain duplicates (In other words, there is no primary key for this table in SQL).\nEach row of this table contains an integer.\n
\n\n

 

\n\n

A single number is a number that appeared only once in the MyNumbers table.

\n\n

Find the largest single number. If there is no single number, report null.

\n\n

The result format is in the following example.

\n \n

 

\n

Example 1:

\n\n
\nInput: \nMyNumbers table:\n+-----+\n| num |\n+-----+\n| 8   |\n| 8   |\n| 3   |\n| 3   |\n| 1   |\n| 4   |\n| 5   |\n| 6   |\n+-----+\nOutput: \n+-----+\n| num |\n+-----+\n| 6   |\n+-----+\nExplanation: The single numbers are 1, 4, 5, and 6.\nSince 6 is the largest single number, we return it.\n
\n\n

Example 2:

\n\n
\nInput: \nMyNumbers table:\n+-----+\n| num |\n+-----+\n| 8   |\n| 8   |\n| 7   |\n| 7   |\n| 3   |\n| 3   |\n| 3   |\n+-----+\nOutput: \n+------+\n| num  |\n+------+\n| null |\n+------+\nExplanation: There are no single numbers in the input table so we return null.\n
\n", + "translatedTitle": "只出现一次的最大数字", + "translatedContent": "

MyNumbers 表:

\n\n
\n
\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| num         | int  |\n+-------------+------+\n该表可能包含重复项(换句话说,在SQL中,该表没有主键)。\n这张表的每一行都含有一个整数。\n
\n\n

 

\n\n

单一数字 是在 MyNumbers 表中只出现一次的数字。

\n\n

找出最大的 单一数字 。如果不存在 单一数字 ,则返回 null

\n\n

查询结果如下例所示。

\n \n\n

 

\n\n

示例 1:

\n\n
\n输入:\nMyNumbers 表:\n+-----+\n| num |\n+-----+\n| 8   |\n| 8   |\n| 3   |\n| 3   |\n| 1   |\n| 4   |\n| 5   |\n| 6   |\n+-----+\n输出:\n+-----+\n| num |\n+-----+\n| 6   |\n+-----+\n解释:单一数字有 1、4、5 和 6 。\n6 是最大的单一数字,返回 6 。\n
\n\n

示例 2:

\n\n
\n输入:\nMyNumbers table:\n+-----+\n| num |\n+-----+\n| 8   |\n| 8   |\n| 7   |\n| 7   |\n| 3   |\n| 3   |\n| 3   |\n+-----+\n输出:\n+------+\n| num  |\n+------+\n| null |\n+------+\n解释:输入的表中不存在单一数字,所以返回 null 。\n
\n
\n
\n\n

 

\n", + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 90, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef biggest_single_number(my_numbers: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"45.2K\", \"totalSubmission\": \"87.1K\", \"totalAcceptedRaw\": 45184, \"totalSubmissionRaw\": 87144, \"acRate\": \"51.8%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\": {\"MyNumbers\": [\"num\"]}, \"rows\": {\"MyNumbers\": [[8],[8],[3],[3],[1],[4],[5],[6]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists MyNumbers (num int)\"],\"mssql\":[\"Create table MyNumbers (num int)\"],\"oraclesql\":[\"Create table MyNumbers (num int)\"],\"database\":true,\"name\":\"biggest_single_number\",\"pythondata\":[\"MyNumbers = pd.DataFrame([], columns=['num']).astype({'num':'Int64'})\"],\"postgresql\":[\"Create table If Not Exists MyNumbers (num int)\"],\"database_schema\":{\"MyNumbers\":{\"num\":\"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists MyNumbers (num int)", + "Truncate table MyNumbers", + "insert into MyNumbers (num) values ('8')", + "insert into MyNumbers (num) values ('8')", + "insert into MyNumbers (num) values ('3')", + "insert into MyNumbers (num) values ('3')", + "insert into MyNumbers (num) values ('1')", + "insert into MyNumbers (num) values ('4')", + "insert into MyNumbers (num) values ('5')", + "insert into MyNumbers (num) values ('6')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\": {\"MyNumbers\": [\"num\"]}, \"rows\": {\"MyNumbers\": [[8],[8],[3],[3],[1],[4],[5],[6]]}}\n{\"headers\": {\"MyNumbers\": [\"num\"]}, \"rows\": {\"MyNumbers\": [[8],[8],[7],[7],[3],[3],[3]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/confirmation-rate.json b/leetcode-cn/originData/confirmation-rate.json new file mode 100644 index 00000000..1f109825 --- /dev/null +++ b/leetcode-cn/originData/confirmation-rate.json @@ -0,0 +1,100 @@ +{ + "data": { + "question": { + "questionId": "2087", + "questionFrontendId": "1934", + "categoryTitle": "Database", + "boundTopicId": 878355, + "title": "Confirmation Rate", + "titleSlug": "confirmation-rate", + "content": "

Table: Signups

\n\n
\n+----------------+----------+\n| Column Name    | Type     |\n+----------------+----------+\n| user_id        | int      |\n| time_stamp     | datetime |\n+----------------+----------+\nuser_id is the column of unique values for this table.\nEach row contains information about the signup time for the user with ID user_id.\n
\n\n

 

\n\n

Table: Confirmations

\n\n
\n+----------------+----------+\n| Column Name    | Type     |\n+----------------+----------+\n| user_id        | int      |\n| time_stamp     | datetime |\n| action         | ENUM     |\n+----------------+----------+\n(user_id, time_stamp) is the primary key (combination of columns with unique values) for this table.\nuser_id is a foreign key (reference column) to the Signups table.\naction is an ENUM (category) of the type ('confirmed', 'timeout')\nEach row of this table indicates that the user with ID user_id requested a confirmation message at time_stamp and that confirmation message was either confirmed ('confirmed') or expired without confirming ('timeout').\n
\n\n

 

\n\n

The confirmation rate of a user is the number of 'confirmed' messages divided by the total number of requested confirmation messages. The confirmation rate of a user that did not request any confirmation messages is 0. Round the confirmation rate to two decimal places.

\n\n

Write a solution to find the confirmation rate of each user.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nSignups table:\n+---------+---------------------+\n| user_id | time_stamp          |\n+---------+---------------------+\n| 3       | 2020-03-21 10:16:13 |\n| 7       | 2020-01-04 13:57:59 |\n| 2       | 2020-07-29 23:09:44 |\n| 6       | 2020-12-09 10:39:37 |\n+---------+---------------------+\nConfirmations table:\n+---------+---------------------+-----------+\n| user_id | time_stamp          | action    |\n+---------+---------------------+-----------+\n| 3       | 2021-01-06 03:30:46 | timeout   |\n| 3       | 2021-07-14 14:00:00 | timeout   |\n| 7       | 2021-06-12 11:57:29 | confirmed |\n| 7       | 2021-06-13 12:58:28 | confirmed |\n| 7       | 2021-06-14 13:59:27 | confirmed |\n| 2       | 2021-01-22 00:00:00 | confirmed |\n| 2       | 2021-02-28 23:59:59 | timeout   |\n+---------+---------------------+-----------+\nOutput: \n+---------+-------------------+\n| user_id | confirmation_rate |\n+---------+-------------------+\n| 6       | 0.00              |\n| 3       | 0.00              |\n| 7       | 1.00              |\n| 2       | 0.50              |\n+---------+-------------------+\nExplanation: \nUser 6 did not request any confirmation messages. The confirmation rate is 0.\nUser 3 made 2 requests and both timed out. The confirmation rate is 0.\nUser 7 made 3 requests and all were confirmed. The confirmation rate is 1.\nUser 2 made 2 requests where one was confirmed and the other timed out. The confirmation rate is 1 / 2 = 0.5.\n
\n", + "translatedTitle": "确认率", + "translatedContent": "

表: Signups

\n\n
\n+----------------+----------+\n| Column Name    | Type     |\n+----------------+----------+\n| user_id        | int      |\n| time_stamp     | datetime |\n+----------------+----------+\nUser_id是该表的主键。\n每一行都包含ID为user_id的用户的注册时间信息。\n
\n\n

 

\n\n

表: Confirmations

\n\n
\n+----------------+----------+\n| Column Name    | Type     |\n+----------------+----------+\n| user_id        | int      |\n| time_stamp     | datetime |\n| action         | ENUM     |\n+----------------+----------+\n(user_id, time_stamp)是该表的主键。\nuser_id是一个引用到注册表的外键。\naction是类型为('confirmed', 'timeout')的ENUM\n该表的每一行都表示ID为user_id的用户在time_stamp请求了一条确认消息,该确认消息要么被确认('confirmed'),要么被过期('timeout')。\n
\n\n

 

\n\n

用户的 确认率 是 'confirmed' 消息的数量除以请求的确认消息的总数。没有请求任何确认消息的用户的确认率为 0 。确认率四舍五入到 小数点后两位

\n\n

编写一个SQL查询来查找每个用户的 确认率 。
\n
\n以 任意顺序 返回结果表。
\n
\n查询结果格式如下所示。
\n
\n示例1:

\n\n
\n输入:\nSignups 表:\n+---------+---------------------+\n| user_id | time_stamp          |\n+---------+---------------------+\n| 3       | 2020-03-21 10:16:13 |\n| 7       | 2020-01-04 13:57:59 |\n| 2       | 2020-07-29 23:09:44 |\n| 6       | 2020-12-09 10:39:37 |\n+---------+---------------------+\nConfirmations 表:\n+---------+---------------------+-----------+\n| user_id | time_stamp          | action    |\n+---------+---------------------+-----------+\n| 3       | 2021-01-06 03:30:46 | timeout   |\n| 3       | 2021-07-14 14:00:00 | timeout   |\n| 7       | 2021-06-12 11:57:29 | confirmed |\n| 7       | 2021-06-13 12:58:28 | confirmed |\n| 7       | 2021-06-14 13:59:27 | confirmed |\n| 2       | 2021-01-22 00:00:00 | confirmed |\n| 2       | 2021-02-28 23:59:59 | timeout   |\n+---------+---------------------+-----------+\n输出: \n+---------+-------------------+\n| user_id | confirmation_rate |\n+---------+-------------------+\n| 6       | 0.00              |\n| 3       | 0.00              |\n| 7       | 1.00              |\n| 2       | 0.50              |\n+---------+-------------------+\n解释:\n用户 6 没有请求任何确认消息。确认率为 0。\n用户 3 进行了 2 次请求,都超时了。确认率为 0。\n用户 7 提出了 3 个请求,所有请求都得到了确认。确认率为 1。\n用户 2 做了 2 个请求,其中一个被确认,另一个超时。确认率为 1 / 2 = 0.5。
\n", + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 58, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef confirmation_rate(signups: pd.DataFrame, confirmations: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"17.6K\", \"totalSubmission\": \"28.4K\", \"totalAcceptedRaw\": 17602, \"totalSubmissionRaw\": 28350, \"acRate\": \"62.1%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\": {\"Signups\": [\"user_id\", \"time_stamp\"], \"Confirmations\": [\"user_id\", \"time_stamp\", \"action\"]}, \"rows\": {\"Signups\": [[3, \"2020-03-21 10:16:13\"], [7, \"2020-01-04 13:57:59\"], [2, \"2020-07-29 23:09:44\"], [6, \"2020-12-09 10:39:37\"]], \"Confirmations\": [[3, \"2021-01-06 03:30:46\", \"timeout\"], [3, \"2021-07-14 14:00:00\", \"timeout\"], [7, \"2021-06-12 11:57:29\", \"confirmed\"], [7, \"2021-06-13 12:58:28\", \"confirmed\"], [7, \"2021-06-14 13:59:27\", \"confirmed\"], [2, \"2021-01-22 00:00:00\", \"confirmed\"], [2, \"2021-02-28 23:59:59\", \"timeout\"]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Signups (user_id int, time_stamp datetime)\",\"Create table If Not Exists Confirmations (user_id int, time_stamp datetime, action ENUM('confirmed','timeout'))\"],\"mssql\":[\"Create table Signups (user_id int, time_stamp datetime)\",\"Create table Confirmations (user_id int, time_stamp datetime, action VARCHAR(10) NOT NULL CHECK (action IN ('confirmed','timeout')))\"],\"oraclesql\":[\"Create table Signups (user_id int, time_stamp date)\",\"Create table Confirmations (user_id int, time_stamp date, action VARCHAR(10) NOT NULL CHECK (action IN ('confirmed','timeout')))\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS'\"],\"database\":true,\"name\":\"confirmation_rate\",\"pythondata\":[\"Signups = pd.DataFrame([], columns=['user_id', 'time_stamp']).astype({'user_id':'Int64', 'time_stamp':'datetime64[ns]'})\",\"Confirmations = pd.DataFrame([], columns=['user_id', 'time_stamp', 'action']).astype({'user_id':'Int64', 'time_stamp':'datetime64[ns]', 'action':'object'})\"],\"postgresql\":[\"Create table If Not Exists Signups (user_id int, time_stamp timestamp)\\n\",\"Create table If Not Exists Confirmations (user_id int, time_stamp timestamp, action VARCHAR(30) CHECK (action IN ('confirmed','timeout')))\\n\"],\"database_schema\":{\"Signups\":{\"user_id\":\"INT\",\"time_stamp\":\"DATETIME\"},\"Confirmations\":{\"user_id\":\"INT\",\"time_stamp\":\"DATETIME\",\"action\":\"ENUM('confirmed', 'timeout')\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Signups (user_id int, time_stamp datetime)", + "Create table If Not Exists Confirmations (user_id int, time_stamp datetime, action ENUM('confirmed','timeout'))", + "Truncate table Signups", + "insert into Signups (user_id, time_stamp) values ('3', '2020-03-21 10:16:13')", + "insert into Signups (user_id, time_stamp) values ('7', '2020-01-04 13:57:59')", + "insert into Signups (user_id, time_stamp) values ('2', '2020-07-29 23:09:44')", + "insert into Signups (user_id, time_stamp) values ('6', '2020-12-09 10:39:37')", + "Truncate table Confirmations", + "insert into Confirmations (user_id, time_stamp, action) values ('3', '2021-01-06 03:30:46', 'timeout')", + "insert into Confirmations (user_id, time_stamp, action) values ('3', '2021-07-14 14:00:00', 'timeout')", + "insert into Confirmations (user_id, time_stamp, action) values ('7', '2021-06-12 11:57:29', 'confirmed')", + "insert into Confirmations (user_id, time_stamp, action) values ('7', '2021-06-13 12:58:28', 'confirmed')", + "insert into Confirmations (user_id, time_stamp, action) values ('7', '2021-06-14 13:59:27', 'confirmed')", + "insert into Confirmations (user_id, time_stamp, action) values ('2', '2021-01-22 00:00:00', 'confirmed')", + "insert into Confirmations (user_id, time_stamp, action) values ('2', '2021-02-28 23:59:59', 'timeout')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\": {\"Signups\": [\"user_id\", \"time_stamp\"], \"Confirmations\": [\"user_id\", \"time_stamp\", \"action\"]}, \"rows\": {\"Signups\": [[3, \"2020-03-21 10:16:13\"], [7, \"2020-01-04 13:57:59\"], [2, \"2020-07-29 23:09:44\"], [6, \"2020-12-09 10:39:37\"]], \"Confirmations\": [[3, \"2021-01-06 03:30:46\", \"timeout\"], [3, \"2021-07-14 14:00:00\", \"timeout\"], [7, \"2021-06-12 11:57:29\", \"confirmed\"], [7, \"2021-06-13 12:58:28\", \"confirmed\"], [7, \"2021-06-14 13:59:27\", \"confirmed\"], [2, \"2021-01-22 00:00:00\", \"confirmed\"], [2, \"2021-02-28 23:59:59\", \"timeout\"]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/count-salary-categories.json b/leetcode-cn/originData/count-salary-categories.json new file mode 100644 index 00000000..b68bec21 --- /dev/null +++ b/leetcode-cn/originData/count-salary-categories.json @@ -0,0 +1,91 @@ +{ + "data": { + "question": { + "questionId": "2057", + "questionFrontendId": "1907", + "categoryTitle": "Database", + "boundTopicId": 841394, + "title": "Count Salary Categories", + "titleSlug": "count-salary-categories", + "content": "

Table: Accounts

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| account_id  | int  |\n| income      | int  |\n+-------------+------+\naccount_id is the primary key (column with unique values) for this table.\nEach row contains information about the monthly income for one bank account.\n
\n\n

 

\n\n

Write a solution to calculate the number of bank accounts for each salary category. The salary categories are:

\n\n
    \n\t
  • "Low Salary": All the salaries strictly less than $20000.
  • \n\t
  • "Average Salary": All the salaries in the inclusive range [$20000, $50000].
  • \n\t
  • "High Salary": All the salaries strictly greater than $50000.
  • \n
\n\n

The result table must contain all three categories. If there are no accounts in a category, return 0.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nAccounts table:\n+------------+--------+\n| account_id | income |\n+------------+--------+\n| 3          | 108939 |\n| 2          | 12747  |\n| 8          | 87709  |\n| 6          | 91796  |\n+------------+--------+\nOutput: \n+----------------+----------------+\n| category       | accounts_count |\n+----------------+----------------+\n| Low Salary     | 1              |\n| Average Salary | 0              |\n| High Salary    | 3              |\n+----------------+----------------+\nExplanation: \nLow Salary: Account 2.\nAverage Salary: No accounts.\nHigh Salary: Accounts 3, 6, and 8.\n
\n", + "translatedTitle": "按分类统计薪水", + "translatedContent": "

表: Accounts

\n\n
\n+-------------+------+\n| 列名        | 类型  |\n+-------------+------+\n| account_id  | int  |\n| income      | int  |\n+-------------+------+\n在 SQL 中,account_id 是这个表的主键。\n每一行都包含一个银行帐户的月收入的信息。\n
\n\n

 

\n\n

查询每个工资类别的银行账户数量。 工资类别如下:

\n\n
    \n\t
  • \"Low Salary\":所有工资 严格低于 20000 美元。
  • \n\t
  • \"Average Salary\"包含 范围内的所有工资 [$20000, $50000]
  • \n\t
  • \n\t

    \"High Salary\":所有工资 严格大于 50000 美元。

    \n\t
  • \n
\n\n

结果表 必须 包含所有三个类别。 如果某个类别中没有帐户,则报告 0

\n\n

任意顺序 返回结果表。

\n\n

查询结果格式如下示例。

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nAccounts 表:\n+------------+--------+\n| account_id | income |\n+------------+--------+\n| 3          | 108939 |\n| 2          | 12747  |\n| 8          | 87709  |\n| 6          | 91796  |\n+------------+--------+\n输出:\n+----------------+----------------+\n| category       | accounts_count |\n+----------------+----------------+\n| Low Salary     | 1              |\n| Average Salary | 0              |\n| High Salary    | 3              |\n+----------------+----------------+\n解释:\n低薪: 有一个账户 2.\n中等薪水: 没有.\n高薪: 有三个账户,他们是 3, 6和 8.
\n", + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 42, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef count_salary_categories(accounts: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"13.4K\", \"totalSubmission\": \"20.9K\", \"totalAcceptedRaw\": 13361, \"totalSubmissionRaw\": 20932, \"acRate\": \"63.8%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Accounts\":[\"account_id\",\"income\"]},\"rows\":{\"Accounts\":[[3,108939],[2,12747],[8,87709],[6,91796]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Accounts (account_id int, income int)\"],\"mssql\":[\"Create table Accounts (account_id int, income int)\"],\"oraclesql\":[\"Create table Accounts (account_id int, income int)\"],\"database\":true,\"name\":\"count_salary_categories\",\"pythondata\":[\"Accounts = pd.DataFrame([], columns=['account_id', 'income']).astype({'account_id':'Int64', 'income':'Int64'})\"],\"postgresql\":[\"Create table If Not Exists Accounts (account_id int, income int)\"],\"database_schema\":{\"Accounts\":{\"account_id\":\"INT\",\"income\":\"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Accounts (account_id int, income int)", + "Truncate table Accounts", + "insert into Accounts (account_id, income) values ('3', '108939')", + "insert into Accounts (account_id, income) values ('2', '12747')", + "insert into Accounts (account_id, income) values ('8', '87709')", + "insert into Accounts (account_id, income) values ('6', '91796')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Accounts\":[\"account_id\",\"income\"]},\"rows\":{\"Accounts\":[[3,108939],[2,12747],[8,87709],[6,91796]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/customers-who-bought-all-products.json b/leetcode-cn/originData/customers-who-bought-all-products.json new file mode 100644 index 00000000..b5c2775b --- /dev/null +++ b/leetcode-cn/originData/customers-who-bought-all-products.json @@ -0,0 +1,96 @@ +{ + "data": { + "question": { + "questionId": "1135", + "questionFrontendId": "1045", + "categoryTitle": "Database", + "boundTopicId": 6079, + "title": "Customers Who Bought All Products", + "titleSlug": "customers-who-bought-all-products", + "content": "

Table: Customer

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| customer_id | int     |\n| product_key | int     |\n+-------------+---------+\nThis table may contain duplicates rows. \ncustomer_id is not NULL.\nproduct_key is a foreign key (reference column) to Product table.\n
\n\n

 

\n\n

Table: Product

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| product_key | int     |\n+-------------+---------+\nproduct_key is the primary key (column with unique values) for this table.\n
\n\n

 

\n\n

Write a solution to report the customer ids from the Customer table that bought all the products in the Product table.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nCustomer table:\n+-------------+-------------+\n| customer_id | product_key |\n+-------------+-------------+\n| 1           | 5           |\n| 2           | 6           |\n| 3           | 5           |\n| 3           | 6           |\n| 1           | 6           |\n+-------------+-------------+\nProduct table:\n+-------------+\n| product_key |\n+-------------+\n| 5           |\n| 6           |\n+-------------+\nOutput: \n+-------------+\n| customer_id |\n+-------------+\n| 1           |\n| 3           |\n+-------------+\nExplanation: \nThe customers who bought all the products (5 and 6) are customers with IDs 1 and 3.\n
\n", + "translatedTitle": "买下所有产品的客户", + "translatedContent": "

Customer 表:

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| customer_id | int     |\n| product_key | int     |\n+-------------+---------+\n该表可能包含重复的行。\ncustomer_id 不为 NULL。\nproduct_key 是 Product 表的外键(reference 列)。\n
\n\n

Product 表:

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| product_key | int     |\n+-------------+---------+\nproduct_key 是这张表的主键(具有唯一值的列)。\n
\n\n

 

\n\n

编写解决方案,报告 Customer 表中购买了 Product 表中所有产品的客户的 id。

\n\n

返回结果表 无顺序要求

\n\n

返回结果格式如下所示。

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nCustomer 表:\n+-------------+-------------+\n| customer_id | product_key |\n+-------------+-------------+\n| 1           | 5           |\n| 2           | 6           |\n| 3           | 5           |\n| 3           | 6           |\n| 1           | 6           |\n+-------------+-------------+\nProduct 表:\n+-------------+\n| product_key |\n+-------------+\n| 5           |\n| 6           |\n+-------------+\n输出:\n+-------------+\n| customer_id |\n+-------------+\n| 1           |\n| 3           |\n+-------------+\n解释:\n购买了所有产品(5 和 6)的客户的 id 是 1 和 3 。\n
\n", + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 98, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef find_customers(customer: pd.DataFrame, product: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"33.4K\", \"totalSubmission\": \"56K\", \"totalAcceptedRaw\": 33365, \"totalSubmissionRaw\": 56002, \"acRate\": \"59.6%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Customer\":[\"customer_id\",\"product_key\"],\"Product\":[\"product_key\"]},\"rows\":{\"Customer\":[[1,5],[2,6],[3,5],[3,6],[1,6]],\"Product\":[[5],[6]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Customer (customer_id int, product_key int)\",\"Create table Product (product_key int)\"],\"mssql\":[\"Create table Customer (customer_id int, product_key int)\",\"Create table Product (product_key int)\"],\"oraclesql\":[\"Create table Customer (customer_id int, product_key int)\",\"Create table Product (product_key int)\"],\"database\":true,\"name\":\"find_customers\",\"pythondata\":[\"Customer = pd.DataFrame([], columns=['customer_id', 'product_key']).astype({'customer_id':'Int64', 'product_key':'Int64'})\",\"Product = pd.DataFrame([], columns=['product_key']).astype({'product_key':'Int64'})\"],\"postgresql\":[\"Create table If Not Exists Customer (customer_id int, product_key int)\\n\",\"Create table Product (product_key int)\"],\"database_schema\":{\"Customer\":{\"customer_id\":\"INT\",\"product_key\":\"INT\"},\"Product\":{\"product_key\":\"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Customer (customer_id int, product_key int)", + "Create table Product (product_key int)", + "Truncate table Customer", + "insert into Customer (customer_id, product_key) values ('1', '5')", + "insert into Customer (customer_id, product_key) values ('2', '6')", + "insert into Customer (customer_id, product_key) values ('3', '5')", + "insert into Customer (customer_id, product_key) values ('3', '6')", + "insert into Customer (customer_id, product_key) values ('1', '6')", + "Truncate table Product", + "insert into Product (product_key) values ('5')", + "insert into Product (product_key) values ('6')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Customer\":[\"customer_id\",\"product_key\"],\"Product\":[\"product_key\"]},\"rows\":{\"Customer\":[[1,5],[2,6],[3,5],[3,6],[1,6]],\"Product\":[[5],[6]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/employee-bonus.json b/leetcode-cn/originData/employee-bonus.json new file mode 100644 index 00000000..e62d805e --- /dev/null +++ b/leetcode-cn/originData/employee-bonus.json @@ -0,0 +1,98 @@ +{ + "data": { + "question": { + "questionId": "577", + "questionFrontendId": "577", + "categoryTitle": "Database", + "boundTopicId": 1998, + "title": "Employee Bonus", + "titleSlug": "employee-bonus", + "content": "

Table: Employee

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| empId       | int     |\n| name        | varchar |\n| supervisor  | int     |\n| salary      | int     |\n+-------------+---------+\nempId is the column with unique values for this table.\nEach row of this table indicates the name and the ID of an employee in addition to their salary and the id of their manager.\n
\n\n

 

\n\n

Table: Bonus

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| empId       | int  |\n| bonus       | int  |\n+-------------+------+\nempId is the column of unique values for this table.\nempId is a foreign key (reference column) to empId from the Employee table.\nEach row of this table contains the id of an employee and their respective bonus.\n
\n\n

 

\n\n

Write a solution to report the name and bonus amount of each employee with a bonus less than 1000.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nEmployee table:\n+-------+--------+------------+--------+\n| empId | name   | supervisor | salary |\n+-------+--------+------------+--------+\n| 3     | Brad   | null       | 4000   |\n| 1     | John   | 3          | 1000   |\n| 2     | Dan    | 3          | 2000   |\n| 4     | Thomas | 3          | 4000   |\n+-------+--------+------------+--------+\nBonus table:\n+-------+-------+\n| empId | bonus |\n+-------+-------+\n| 2     | 500   |\n| 4     | 2000  |\n+-------+-------+\nOutput: \n+------+-------+\n| name | bonus |\n+------+-------+\n| Brad | null  |\n| John | null  |\n| Dan  | 500   |\n+------+-------+\n
\n", + "translatedTitle": "员工奖金", + "translatedContent": "

表:Employee 

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| empId       | int     |\n| name        | varchar |\n| supervisor  | int     |\n| salary      | int     |\n+-------------+---------+\nempId 是该表中具有唯一值的列。\n该表的每一行都表示员工的姓名和 id,以及他们的工资和经理的 id。\n
\n\n

 

\n\n

表:Bonus

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| empId       | int  |\n| bonus       | int  |\n+-------------+------+\nempId 是该表具有唯一值的列。\nempId 是 Employee 表中 empId 的外键(reference 列)。\n该表的每一行都包含一个员工的 id 和他们各自的奖金。\n
\n\n

 

\n\n

编写解决方案,报告每个奖金 少于 1000 的员工的姓名和奖金数额。

\n\n

任意顺序 返回结果表。

\n\n

结果格式如下所示。

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nEmployee table:\n+-------+--------+------------+--------+\n| empId | name   | supervisor | salary |\n+-------+--------+------------+--------+\n| 3     | Brad   | null       | 4000   |\n| 1     | John   | 3          | 1000   |\n| 2     | Dan    | 3          | 2000   |\n| 4     | Thomas | 3          | 4000   |\n+-------+--------+------------+--------+\nBonus table:\n+-------+-------+\n| empId | bonus |\n+-------+-------+\n| 2     | 500   |\n| 4     | 2000  |\n+-------+-------+\n输出:\n+------+-------+\n| name | bonus |\n+------+-------+\n| Brad | null  |\n| John | null  |\n| Dan  | 500   |\n+------+-------+
\n", + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 81, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[{\"title\": \"Combine Two Tables\", \"titleSlug\": \"combine-two-tables\", \"difficulty\": \"Easy\", \"translatedTitle\": \"\\u7ec4\\u5408\\u4e24\\u4e2a\\u8868\", \"isPaidOnly\": false}]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef employee_bonus(employee: pd.DataFrame, bonus: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"60.6K\", \"totalSubmission\": \"87.3K\", \"totalAcceptedRaw\": 60572, \"totalSubmissionRaw\": 87291, \"acRate\": \"69.4%\"}", + "hints": [ + "If the EmpId in table Employee has no match in table Bonus, we consider that the corresponding bonus is null and null is smaller than 1000.", + "Inner join is the default join, we can solve the mismatching problem by using outer join." + ], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Employee\":[\"empId\",\"name\",\"supervisor\",\"salary\"],\"Bonus\":[\"empId\",\"bonus\"]},\"rows\":{\"Employee\":[[3,\"Brad\",null,4000],[1,\"John\",3,1000],[2,\"Dan\",3,2000],[4,\"Thomas\",3,4000]],\"Bonus\":[[2,500],[4,2000]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Employee (empId int, name varchar(255), supervisor int, salary int)\",\"Create table If Not Exists Bonus (empId int, bonus int)\"],\"mssql\":[\"Create table Employee (empId int, name varchar(255), supervisor int, salary int)\",\"Create table Bonus (empId int, bonus int)\"],\"oraclesql\":[\"Create table Employee (empId int, name varchar(255), supervisor int, salary int)\",\"Create table Bonus (empId int, bonus int)\"],\"database\":true,\"name\":\"employee_bonus\",\"manual\":false,\"pythondata\":[\"Employee = pd.DataFrame([], columns=['empId', 'name', 'supervisor', 'salary']).astype({'empId':'Int64', 'name':'object', 'supervisor':'Int64', 'salary':'Int64'})\",\"Bonus = pd.DataFrame([], columns=['empId', 'bonus']).astype({'empId':'Int64', 'bonus':'Int64'})\"],\"postgresql\":[\"Create table If Not Exists Employee (empId int, name varchar(255), supervisor int, salary int)\\n\",\"Create table If Not Exists Bonus (empId int, bonus int)\"],\"database_schema\":{\"Employee\":{\"empId\":\"INT\",\"name\":\"VARCHAR(255)\",\"supervisor\":\"INT\",\"salary\":\"INT\"},\"Bonus\":{\"empId\":\"INT\",\"bonus\":\"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Employee (empId int, name varchar(255), supervisor int, salary int)", + "Create table If Not Exists Bonus (empId int, bonus int)", + "Truncate table Employee", + "insert into Employee (empId, name, supervisor, salary) values ('3', 'Brad', 'None', '4000')", + "insert into Employee (empId, name, supervisor, salary) values ('1', 'John', '3', '1000')", + "insert into Employee (empId, name, supervisor, salary) values ('2', 'Dan', '3', '2000')", + "insert into Employee (empId, name, supervisor, salary) values ('4', 'Thomas', '3', '4000')", + "Truncate table Bonus", + "insert into Bonus (empId, bonus) values ('2', '500')", + "insert into Bonus (empId, bonus) values ('4', '2000')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Employee\":[\"empId\",\"name\",\"supervisor\",\"salary\"],\"Bonus\":[\"empId\",\"bonus\"]},\"rows\":{\"Employee\":[[3,\"Brad\",null,4000],[1,\"John\",3,1000],[2,\"Dan\",3,2000],[4,\"Thomas\",3,4000]],\"Bonus\":[[2,500],[4,2000]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/employees-whose-manager-left-the-company.json b/leetcode-cn/originData/employees-whose-manager-left-the-company.json new file mode 100644 index 00000000..b80baaf7 --- /dev/null +++ b/leetcode-cn/originData/employees-whose-manager-left-the-company.json @@ -0,0 +1,93 @@ +{ + "data": { + "question": { + "questionId": "2127", + "questionFrontendId": "1978", + "categoryTitle": "Database", + "boundTopicId": 957284, + "title": "Employees Whose Manager Left the Company", + "titleSlug": "employees-whose-manager-left-the-company", + "content": "

Table: Employees

\n\n
\n+-------------+----------+\n| Column Name | Type     |\n+-------------+----------+\n| employee_id | int      |\n| name        | varchar  |\n| manager_id  | int      |\n| salary      | int      |\n+-------------+----------+\nIn SQL, employee_id is the primary key for this table.\nThis table contains information about the employees, their salary, and the ID of their manager. Some employees do not have a manager (manager_id is null). \n
\n\n

 

\n\n

Find the IDs of the employees whose salary is strictly less than $30000 and whose manager left the company. When a manager leaves the company, their information is deleted from the Employees table, but the reports still have their manager_id set to the manager that left.

\n\n

Return the result table ordered by employee_id.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput:  \nEmployees table:\n+-------------+-----------+------------+--------+\n| employee_id | name      | manager_id | salary |\n+-------------+-----------+------------+--------+\n| 3           | Mila      | 9          | 60301  |\n| 12          | Antonella | null       | 31000  |\n| 13          | Emery     | null       | 67084  |\n| 1           | Kalel     | 11         | 21241  |\n| 9           | Mikaela   | null       | 50937  |\n| 11          | Joziah    | 6          | 28485  |\n+-------------+-----------+------------+--------+\nOutput: \n+-------------+\n| employee_id |\n+-------------+\n| 11          |\n+-------------+\n\nExplanation: \nThe employees with a salary less than $30000 are 1 (Kalel) and 11 (Joziah).\nKalel's manager is employee 11, who is still in the company (Joziah).\nJoziah's manager is employee 6, who left the company because there is no row for employee 6 as it was deleted.\n
\n", + "translatedTitle": "上级经理已离职的公司员工", + "translatedContent": "

表: Employees

\n\n
\n+-------------+----------+\n| Column Name | Type     |\n+-------------+----------+\n| employee_id | int      |\n| name        | varchar  |\n| manager_id  | int      |\n| salary      | int      |\n+-------------+----------+\n在 SQL 中,employee_id 是这个表的主键。\n这个表包含了员工,他们的薪水和上级经理的id。\n有一些员工没有上级经理(其 manager_id 是空值)。\n
\n\n

 

\n\n

查找这些员工的id,他们的薪水严格少于$30000 并且他们的上级经理已离职。当一个经理离开公司时,他们的信息需要从员工表中删除掉,但是表中的员工的manager_id  这一列还是设置的离职经理的id 。

\n\n

返回的结果按照employee_id 从小到大排序。

\n\n

查询结果如下所示:

\n\n

 

\n\n

示例:

\n\n
\n输入:\nEmployees table:\n+-------------+-----------+------------+--------+\n| employee_id | name      | manager_id | salary |\n+-------------+-----------+------------+--------+\n| 3           | Mila      | 9          | 60301  |\n| 12          | Antonella | null       | 31000  |\n| 13          | Emery     | null       | 67084  |\n| 1           | Kalel     | 11         | 21241  |\n| 9           | Mikaela   | null       | 50937  |\n| 11          | Joziah    | 6          | 28485  |\n+-------------+-----------+------------+--------+\n输出:\n+-------------+\n| employee_id |\n+-------------+\n| 11          |\n+-------------+\n\n解释:\n薪水少于 30000 美元的员工有 1 号(Kalel) 和 11号 (Joziah)。\nKalel 的上级经理是 11 号员工,他还在公司上班(他是 Joziah )。\nJoziah 的上级经理是 6 号员工,他已经离职,因为员工表里面已经没有 6 号员工的信息了,它被删除了。\n
\n", + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 23, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef find_employees(employees: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"13.2K\", \"totalSubmission\": \"27.7K\", \"totalAcceptedRaw\": 13234, \"totalSubmissionRaw\": 27706, \"acRate\": \"47.8%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\": {\"Employees\": [\"employee_id\", \"name\", \"manager_id\", \"salary\"]}, \"rows\": {\"Employees\": [[3, \"Mila\", 9, 60301], [12, \"Antonella\", null, 31000], [13, \"Emery\", null, 67084], [1, \"Kalel\", 11, 21241], [9, \"Mikaela\", null, 50937], [11, \"Joziah\", 6, 28485]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Employees (employee_id int, name varchar(20), manager_id int, salary int)\"],\"mssql\":[\"Create table Employees (employee_id int, name varchar(20), manager_id int, salary int)\"],\"oraclesql\":[\"Create table Employees (employee_id int, name varchar(20), manager_id int, salary int)\"],\"database\":true,\"name\":\"find_employees\",\"pythondata\":[\"Employees = pd.DataFrame([], columns=['employee_id', 'name', 'manager_id', 'salary']).astype({'employee_id':'Int64', 'name':'object', 'manager_id':'Int64', 'salary':'Int64'})\"],\"postgresql\":[\"Create table If Not Exists Employees (employee_id int, name varchar(20), manager_id int, salary int)\"],\"database_schema\":{\"Employees\":{\"employee_id\":\"INT\",\"name\":\"VARCHAR(20)\",\"manager_id\":\"INT\",\"salary\":\"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Employees (employee_id int, name varchar(20), manager_id int, salary int)", + "Truncate table Employees", + "insert into Employees (employee_id, name, manager_id, salary) values ('3', 'Mila', '9', '60301')", + "insert into Employees (employee_id, name, manager_id, salary) values ('12', 'Antonella', 'None', '31000')", + "insert into Employees (employee_id, name, manager_id, salary) values ('13', 'Emery', 'None', '67084')", + "insert into Employees (employee_id, name, manager_id, salary) values ('1', 'Kalel', '11', '21241')", + "insert into Employees (employee_id, name, manager_id, salary) values ('9', 'Mikaela', 'None', '50937')", + "insert into Employees (employee_id, name, manager_id, salary) values ('11', 'Joziah', '6', '28485')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\": {\"Employees\": [\"employee_id\", \"name\", \"manager_id\", \"salary\"]}, \"rows\": {\"Employees\": [[3, \"Mila\", 9, 60301], [12, \"Antonella\", null, 31000], [13, \"Emery\", null, 67084], [1, \"Kalel\", 11, 21241], [9, \"Mikaela\", null, 50937], [11, \"Joziah\", 6, 28485]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/find-users-with-valid-e-mails.json b/leetcode-cn/originData/find-users-with-valid-e-mails.json new file mode 100644 index 00000000..9aa79203 --- /dev/null +++ b/leetcode-cn/originData/find-users-with-valid-e-mails.json @@ -0,0 +1,94 @@ +{ + "data": { + "question": { + "questionId": "1664", + "questionFrontendId": "1517", + "categoryTitle": "Database", + "boundTopicId": 336736, + "title": "Find Users With Valid E-Mails", + "titleSlug": "find-users-with-valid-e-mails", + "content": "

Table: Users

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| name          | varchar |\n| mail          | varchar |\n+---------------+---------+\nuser_id is the primary key (column with unique values) for this table.\nThis table contains information of the users signed up in a website. Some e-mails are invalid.\n
\n\n

 

\n\n

Write a solution to find the users who have valid emails.

\n\n

A valid e-mail has a prefix name and a domain where:

\n\n
    \n\t
  • The prefix name is a string that may contain letters (upper or lower case), digits, underscore '_', period '.', and/or dash '-'. The prefix name must start with a letter.
  • \n\t
  • The domain is '@leetcode.com'.
  • \n
\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nUsers table:\n+---------+-----------+-------------------------+\n| user_id | name      | mail                    |\n+---------+-----------+-------------------------+\n| 1       | Winston   | winston@leetcode.com    |\n| 2       | Jonathan  | jonathanisgreat         |\n| 3       | Annabelle | bella-@leetcode.com     |\n| 4       | Sally     | sally.come@leetcode.com |\n| 5       | Marwan    | quarz#2020@leetcode.com |\n| 6       | David     | david69@gmail.com       |\n| 7       | Shapiro   | .shapo@leetcode.com     |\n+---------+-----------+-------------------------+\nOutput: \n+---------+-----------+-------------------------+\n| user_id | name      | mail                    |\n+---------+-----------+-------------------------+\n| 1       | Winston   | winston@leetcode.com    |\n| 3       | Annabelle | bella-@leetcode.com     |\n| 4       | Sally     | sally.come@leetcode.com |\n+---------+-----------+-------------------------+\nExplanation: \nThe mail of user 2 does not have a domain.\nThe mail of user 5 has the # sign which is not allowed.\nThe mail of user 6 does not have the leetcode domain.\nThe mail of user 7 starts with a period.\n
\n", + "translatedTitle": "查找拥有有效邮箱的用户", + "translatedContent": "

表: Users

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| name          | varchar |\n| mail          | varchar |\n+---------------+---------+\nuser_id 是该表的主键(具有唯一值的列)。\n该表包含了网站已注册用户的信息。有一些电子邮件是无效的。\n
\n\n

 

\n\n

编写一个解决方案,以查找具有有效电子邮件的用户。

\n\n

一个有效的电子邮件具有前缀名称和域,其中:

\n\n
    \n\t
  1.  前缀 名称是一个字符串,可以包含字母(大写或小写),数字,下划线 '_' ,点 '.' 和/或破折号 '-' 。前缀名称 必须 以字母开头。
  2. \n\t
  3. '@leetcode.com'
  4. \n
\n\n

以任何顺序返回结果表。

\n\n

结果的格式如以下示例所示:

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nUsers 表:\n+---------+-----------+-------------------------+\n| user_id | name      | mail                    |\n+---------+-----------+-------------------------+\n| 1       | Winston   | winston@leetcode.com    |\n| 2       | Jonathan  | jonathanisgreat         |\n| 3       | Annabelle | bella-@leetcode.com     |\n| 4       | Sally     | sally.come@leetcode.com |\n| 5       | Marwan    | quarz#2020@leetcode.com |\n| 6       | David     | david69@gmail.com       |\n| 7       | Shapiro   | .shapo@leetcode.com     |\n+---------+-----------+-------------------------+\n输出:\n+---------+-----------+-------------------------+\n| user_id | name      | mail                    |\n+---------+-----------+-------------------------+\n| 1       | Winston   | winston@leetcode.com    |\n| 3       | Annabelle | bella-@leetcode.com     |\n| 4       | Sally     | sally.come@leetcode.com |\n+---------+-----------+-------------------------+\n解释:\n用户 2 的电子邮件没有域。 \n用户 5 的电子邮件带有不允许的 '#' 符号。\n用户 6 的电子邮件没有 leetcode 域。 \n用户 7 的电子邮件以点开头。\n
\n", + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 75, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef valid_emails(users: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"18.2K\", \"totalSubmission\": \"34.3K\", \"totalAcceptedRaw\": 18200, \"totalSubmissionRaw\": 34306, \"acRate\": \"53.1%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Users\":[\"user_id\",\"name\",\"mail\"]},\"rows\":{\"Users\":[[1,\"Winston\",\"winston@leetcode.com\"],[2,\"Jonathan\",\"jonathanisgreat\"],[3,\"Annabelle\",\"bella-@leetcode.com\"],[4,\"Sally\",\"sally.come@leetcode.com\"],[5,\"Marwan\",\"quarz#2020@leetcode.com\"],[6,\"David\",\"david69@gmail.com\"],[7,\"Shapiro\",\".shapo@leetcode.com\"]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Users (user_id int, name varchar(30), mail varchar(50))\"],\"mssql\":[\"Create table Users (user_id int, name varchar(30), mail varchar(50))\"],\"oraclesql\":[\"Create table Users (user_id int, name varchar(30), mail varchar(50))\"],\"database\":true,\"name\":\"valid_emails\",\"pythondata\":[\"Users = pd.DataFrame([], columns=['user_id', 'name', 'mail']).astype({'user_id':'int64', 'name':'object', 'mail':'object'})\"],\"postgresql\":[\"\\nCreate table If Not Exists Users (user_id int, name varchar(30), mail varchar(50))\"],\"database_schema\":{\"Users\":{\"user_id\":\"INT\",\"name\":\"VARCHAR(30)\",\"mail\":\"VARCHAR(50)\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Users (user_id int, name varchar(30), mail varchar(50))", + "Truncate table Users", + "insert into Users (user_id, name, mail) values ('1', 'Winston', 'winston@leetcode.com')", + "insert into Users (user_id, name, mail) values ('2', 'Jonathan', 'jonathanisgreat')", + "insert into Users (user_id, name, mail) values ('3', 'Annabelle', 'bella-@leetcode.com')", + "insert into Users (user_id, name, mail) values ('4', 'Sally', 'sally.come@leetcode.com')", + "insert into Users (user_id, name, mail) values ('5', 'Marwan', 'quarz#2020@leetcode.com')", + "insert into Users (user_id, name, mail) values ('6', 'David', 'david69@gmail.com')", + "insert into Users (user_id, name, mail) values ('7', 'Shapiro', '.shapo@leetcode.com')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Users\":[\"user_id\",\"name\",\"mail\"]},\"rows\":{\"Users\":[[1,\"Winston\",\"winston@leetcode.com\"],[2,\"Jonathan\",\"jonathanisgreat\"],[3,\"Annabelle\",\"bella-@leetcode.com\"],[4,\"Sally\",\"sally.come@leetcode.com\"],[5,\"Marwan\",\"quarz#2020@leetcode.com\"],[6,\"David\",\"david69@gmail.com\"],[7,\"Shapiro\",\".shapo@leetcode.com\"]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/friend-requests-ii-who-has-the-most-friends.json b/leetcode-cn/originData/friend-requests-ii-who-has-the-most-friends.json new file mode 100644 index 00000000..256c6ccd --- /dev/null +++ b/leetcode-cn/originData/friend-requests-ii-who-has-the-most-friends.json @@ -0,0 +1,93 @@ +{ + "data": { + "question": { + "questionId": "602", + "questionFrontendId": "602", + "categoryTitle": "Database", + "boundTopicId": 2640, + "title": "Friend Requests II: Who Has the Most Friends", + "titleSlug": "friend-requests-ii-who-has-the-most-friends", + "content": "

Table: RequestAccepted

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| requester_id   | int     |\n| accepter_id    | int     |\n| accept_date    | date    |\n+----------------+---------+\n(requester_id, accepter_id) is the primary key (combination of columns with unique values) for this table.\nThis table contains the ID of the user who sent the request, the ID of the user who received the request, and the date when the request was accepted.\n
\n\n

 

\n\n

Write a solution to find the people who have the most friends and the most friends number.

\n\n

The test cases are generated so that only one person has the most friends.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nRequestAccepted table:\n+--------------+-------------+-------------+\n| requester_id | accepter_id | accept_date |\n+--------------+-------------+-------------+\n| 1            | 2           | 2016/06/03  |\n| 1            | 3           | 2016/06/08  |\n| 2            | 3           | 2016/06/08  |\n| 3            | 4           | 2016/06/09  |\n+--------------+-------------+-------------+\nOutput: \n+----+-----+\n| id | num |\n+----+-----+\n| 3  | 3   |\n+----+-----+\nExplanation: \nThe person with id 3 is a friend of people 1, 2, and 4, so he has three friends in total, which is the most number than any others.\n
\n\n

 

\n

Follow up: In the real world, multiple people could have the same most number of friends. Could you find all these people in this case?

\n", + "translatedTitle": "好友申请 II :谁有最多的好友", + "translatedContent": "

RequestAccepted 表:

\n\n
\n
\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| requester_id   | int     |\n| accepter_id    | int     |\n| accept_date    | date    |\n+----------------+---------+\n(requester_id, accepter_id) 是这张表的主键(具有唯一值的列的组合)。\n这张表包含发送好友请求的人的 ID ,接收好友请求的人的 ID ,以及好友请求通过的日期。\n
\n\n

 

\n\n

编写解决方案,找出拥有最多的好友的人和他拥有的好友数目。

\n\n

生成的测试用例保证拥有最多好友数目的只有 1 个人。

\n\n

查询结果格式如下例所示。

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nRequestAccepted 表:\n+--------------+-------------+-------------+\n| requester_id | accepter_id | accept_date |\n+--------------+-------------+-------------+\n| 1            | 2           | 2016/06/03  |\n| 1            | 3           | 2016/06/08  |\n| 2            | 3           | 2016/06/08  |\n| 3            | 4           | 2016/06/09  |\n+--------------+-------------+-------------+\n输出:\n+----+-----+\n| id | num |\n+----+-----+\n| 3  | 3   |\n+----+-----+\n解释:\n编号为 3 的人是编号为 1 ,2 和 4 的人的好友,所以他总共有 3 个好友,比其他人都多。
\n\n

 

\n\n

进阶:在真实世界里,可能会有多个人拥有好友数相同且最多,你能找到所有这些人吗?

\n
\n
\n", + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 95, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef most_friends(request_accepted: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"27.7K\", \"totalSubmission\": \"46K\", \"totalAcceptedRaw\": 27686, \"totalSubmissionRaw\": 45980, \"acRate\": \"60.2%\"}", + "hints": [ + "Being friends is bidirectional. If you accept someone's adding friend request, both you and the other person will have one more friend." + ], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"RequestAccepted\":[\"requester_id\",\"accepter_id\",\"accept_date\"]},\"rows\":{\"RequestAccepted\":[[1,2,\"2016/06/03\"],[1,3,\"2016/06/08\"],[2,3,\"2016/06/08\"],[3,4,\"2016/06/09\"]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists RequestAccepted (requester_id int not null, accepter_id int null, accept_date date null)\"],\"mssql\":[\"Create table RequestAccepted (requester_id int not null, accepter_id int null, accept_date date null)\"],\"oraclesql\":[\"Create table RequestAccepted (requester_id int not null, accepter_id int null, accept_date date null)\",\"Alter SESSION set NLS_DATE_FORMAT = 'YYYY\\/MM\\/DD'\"],\"database\":true,\"name\":\"most_friends\",\"pythondata\":[\"RequestAccepted = pd.DataFrame([], columns=['requester_id', 'accepter_id', 'accept_date']).astype({'requester_id':'Int64', 'accepter_id':'Int64', 'accept_date':'datetime64[ns]'})\"],\"postgresql\":[\"\\nCreate table If Not Exists RequestAccepted (requester_id int not null, accepter_id int null, accept_date date null)\"],\"database_schema\":{\"RequestAccepted\":{\"requester_id\":\"INT\",\"accepter_id\":\"INT\",\"accept_date\":\"DATE\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists RequestAccepted (requester_id int not null, accepter_id int null, accept_date date null)", + "Truncate table RequestAccepted", + "insert into RequestAccepted (requester_id, accepter_id, accept_date) values ('1', '2', '2016/06/03')", + "insert into RequestAccepted (requester_id, accepter_id, accept_date) values ('1', '3', '2016/06/08')", + "insert into RequestAccepted (requester_id, accepter_id, accept_date) values ('2', '3', '2016/06/08')", + "insert into RequestAccepted (requester_id, accepter_id, accept_date) values ('3', '4', '2016/06/09')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"RequestAccepted\":[\"requester_id\",\"accepter_id\",\"accept_date\"]},\"rows\":{\"RequestAccepted\":[[1,2,\"2016/06/03\"],[1,3,\"2016/06/08\"],[2,3,\"2016/06/08\"],[3,4,\"2016/06/09\"]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/game-play-analysis-iv.json b/leetcode-cn/originData/game-play-analysis-iv.json new file mode 100644 index 00000000..89e50df6 --- /dev/null +++ b/leetcode-cn/originData/game-play-analysis-iv.json @@ -0,0 +1,92 @@ +{ + "data": { + "question": { + "questionId": "1182", + "questionFrontendId": "550", + "categoryTitle": "Database", + "boundTopicId": 11038, + "title": "Game Play Analysis IV", + "titleSlug": "game-play-analysis-iv", + "content": "

Table: Activity

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| player_id    | int     |\n| device_id    | int     |\n| event_date   | date    |\n| games_played | int     |\n+--------------+---------+\n(player_id, event_date) is the primary key (combination of columns with unique values) of this table.\nThis table shows the activity of players of some games.\nEach row is a record of a player who logged in and played a number of games (possibly 0) before logging out on someday using some device.\n
\n\n

 

\n\n

Write a solution to report the fraction of players that logged in again on the day after the day they first logged in, rounded to 2 decimal places. In other words, you need to count the number of players that logged in for at least two consecutive days starting from their first login date, then divide that number by the total number of players.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nActivity table:\n+-----------+-----------+------------+--------------+\n| player_id | device_id | event_date | games_played |\n+-----------+-----------+------------+--------------+\n| 1         | 2         | 2016-03-01 | 5            |\n| 1         | 2         | 2016-03-02 | 6            |\n| 2         | 3         | 2017-06-25 | 1            |\n| 3         | 1         | 2016-03-02 | 0            |\n| 3         | 4         | 2018-07-03 | 5            |\n+-----------+-----------+------------+--------------+\nOutput: \n+-----------+\n| fraction  |\n+-----------+\n| 0.33      |\n+-----------+\nExplanation: \nOnly the player with id 1 logged back in after the first day he had logged in so the answer is 1/3 = 0.33\n
\n", + "translatedTitle": "游戏玩法分析 IV", + "translatedContent": "

Table: Activity

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| player_id    | int     |\n| device_id    | int     |\n| event_date   | date    |\n| games_played | int     |\n+--------------+---------+\n(player_id,event_date)是此表的主键(具有唯一值的列的组合)。\n这张表显示了某些游戏的玩家的活动情况。\n每一行是一个玩家的记录,他在某一天使用某个设备注销之前登录并玩了很多游戏(可能是 0)。\n
\n\n

 

\n\n

编写解决方案,报告在首次登录的第二天再次登录的玩家的 比率四舍五入到小数点后两位。换句话说,你需要计算从首次登录日期开始至少连续两天登录的玩家的数量,然后除以玩家总数。

\n\n

结果格式如下所示:

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nActivity table:\n+-----------+-----------+------------+--------------+\n| player_id | device_id | event_date | games_played |\n+-----------+-----------+------------+--------------+\n| 1         | 2         | 2016-03-01 | 5            |\n| 1         | 2         | 2016-03-02 | 6            |\n| 2         | 3         | 2017-06-25 | 1            |\n| 3         | 1         | 2016-03-02 | 0            |\n| 3         | 4         | 2018-07-03 | 5            |\n+-----------+-----------+------------+--------------+\n输出:\n+-----------+\n| fraction  |\n+-----------+\n| 0.33      |\n+-----------+\n解释:\n只有 ID 为 1 的玩家在第一天登录后才重新登录,所以答案是 1/3 = 0.33\n
\n", + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 185, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[{\"title\": \"Game Play Analysis III\", \"titleSlug\": \"game-play-analysis-iii\", \"difficulty\": \"Medium\", \"translatedTitle\": \"\\u6e38\\u620f\\u73a9\\u6cd5\\u5206\\u6790 III\", \"isPaidOnly\": true}, {\"title\": \"Game Play Analysis V\", \"titleSlug\": \"game-play-analysis-v\", \"difficulty\": \"Hard\", \"translatedTitle\": \"\\u6e38\\u620f\\u73a9\\u6cd5\\u5206\\u6790 V\", \"isPaidOnly\": true}]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef gameplay_analysis(activity: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"45.5K\", \"totalSubmission\": \"110K\", \"totalAcceptedRaw\": 45531, \"totalSubmissionRaw\": 109989, \"acRate\": \"41.4%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Activity\":[\"player_id\",\"device_id\",\"event_date\",\"games_played\"]},\"rows\":{\"Activity\":[[1,2,\"2016-03-01\",5],[1,2,\"2016-03-02\",6],[2,3,\"2017-06-25\",1],[3,1,\"2016-03-02\",0],[3,4,\"2018-07-03\",5]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Activity (player_id int, device_id int, event_date date, games_played int)\"],\"mssql\":[\"Create table Activity (player_id int, device_id int, event_date date, games_played int)\"],\"oraclesql\":[\"Create table Activity (player_id int, device_id int, event_date date, games_played int)\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"],\"database\":true,\"name\":\"gameplay_analysis\",\"pythondata\":[\"Activity = pd.DataFrame([], columns=['player_id', 'device_id', 'event_date', 'games_played']).astype({'player_id':'Int64', 'device_id':'Int64', 'event_date':'datetime64[ns]', 'games_played':'Int64'})\"],\"postgresql\":[\"\\nCreate table If Not Exists Activity (player_id int, device_id int, event_date date, games_played int)\"],\"database_schema\":{\"Activity\":{\"player_id\":\"INT\",\"device_id\":\"INT\",\"event_date\":\"DATE\",\"games_played\":\"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Activity (player_id int, device_id int, event_date date, games_played int)", + "Truncate table Activity", + "insert into Activity (player_id, device_id, event_date, games_played) values ('1', '2', '2016-03-01', '5')", + "insert into Activity (player_id, device_id, event_date, games_played) values ('1', '2', '2016-03-02', '6')", + "insert into Activity (player_id, device_id, event_date, games_played) values ('2', '3', '2017-06-25', '1')", + "insert into Activity (player_id, device_id, event_date, games_played) values ('3', '1', '2016-03-02', '0')", + "insert into Activity (player_id, device_id, event_date, games_played) values ('3', '4', '2018-07-03', '5')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Activity\":[\"player_id\",\"device_id\",\"event_date\",\"games_played\"]},\"rows\":{\"Activity\":[[1,2,\"2016-03-01\",5],[1,2,\"2016-03-02\",6],[2,3,\"2017-06-25\",1],[3,1,\"2016-03-02\",0],[3,4,\"2018-07-03\",5]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/immediate-food-delivery-ii.json b/leetcode-cn/originData/immediate-food-delivery-ii.json new file mode 100644 index 00000000..8be2d5d4 --- /dev/null +++ b/leetcode-cn/originData/immediate-food-delivery-ii.json @@ -0,0 +1,94 @@ +{ + "data": { + "question": { + "questionId": "1292", + "questionFrontendId": "1174", + "categoryTitle": "Database", + "boundTopicId": 33159, + "title": "Immediate Food Delivery II", + "titleSlug": "immediate-food-delivery-ii", + "content": "

Table: Delivery

\n\n
\n+-----------------------------+---------+\n| Column Name                 | Type    |\n+-----------------------------+---------+\n| delivery_id                 | int     |\n| customer_id                 | int     |\n| order_date                  | date    |\n| customer_pref_delivery_date | date    |\n+-----------------------------+---------+\ndelivery_id is the column of unique values of this table.\nThe table holds information about food delivery to customers that make orders at some date and specify a preferred delivery date (on the same order date or after it).\n
\n\n

 

\n\n

If the customer's preferred delivery date is the same as the order date, then the order is called immediate; otherwise, it is called scheduled.

\n\n

The first order of a customer is the order with the earliest order date that the customer made. It is guaranteed that a customer has precisely one first order.

\n\n

Write a solution to find the percentage of immediate orders in the first orders of all customers, rounded to 2 decimal places.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nDelivery table:\n+-------------+-------------+------------+-----------------------------+\n| delivery_id | customer_id | order_date | customer_pref_delivery_date |\n+-------------+-------------+------------+-----------------------------+\n| 1           | 1           | 2019-08-01 | 2019-08-02                  |\n| 2           | 2           | 2019-08-02 | 2019-08-02                  |\n| 3           | 1           | 2019-08-11 | 2019-08-12                  |\n| 4           | 3           | 2019-08-24 | 2019-08-24                  |\n| 5           | 3           | 2019-08-21 | 2019-08-22                  |\n| 6           | 2           | 2019-08-11 | 2019-08-13                  |\n| 7           | 4           | 2019-08-09 | 2019-08-09                  |\n+-------------+-------------+------------+-----------------------------+\nOutput: \n+----------------------+\n| immediate_percentage |\n+----------------------+\n| 50.00                |\n+----------------------+\nExplanation: \nThe customer id 1 has a first order with delivery id 1 and it is scheduled.\nThe customer id 2 has a first order with delivery id 2 and it is immediate.\nThe customer id 3 has a first order with delivery id 5 and it is scheduled.\nThe customer id 4 has a first order with delivery id 7 and it is immediate.\nHence, half the customers have immediate first orders.\n
\n", + "translatedTitle": "即时食物配送 II", + "translatedContent": "

配送表: Delivery

\n\n
\n+-----------------------------+---------+\n| Column Name                 | Type    |\n+-----------------------------+---------+\n| delivery_id                 | int     |\n| customer_id                 | int     |\n| order_date                  | date    |\n| customer_pref_delivery_date | date    |\n+-----------------------------+---------+\ndelivery_id 是该表中具有唯一值的列。\n该表保存着顾客的食物配送信息,顾客在某个日期下了订单,并指定了一个期望的配送日期(和下单日期相同或者在那之后)。\n
\n\n

 

\n\n

如果顾客期望的配送日期和下单日期相同,则该订单称为 「即时订单」,否则称为「计划订单」。

\n\n

首次订单」是顾客最早创建的订单。我们保证一个顾客只会有一个「首次订单」。

\n\n

编写解决方案以获取即时订单在所有用户的首次订单中的比例。保留两位小数。

\n\n

结果示例如下所示:

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nDelivery 表:\n+-------------+-------------+------------+-----------------------------+\n| delivery_id | customer_id | order_date | customer_pref_delivery_date |\n+-------------+-------------+------------+-----------------------------+\n| 1           | 1           | 2019-08-01 | 2019-08-02                  |\n| 2           | 2           | 2019-08-02 | 2019-08-02                  |\n| 3           | 1           | 2019-08-11 | 2019-08-12                  |\n| 4           | 3           | 2019-08-24 | 2019-08-24                  |\n| 5           | 3           | 2019-08-21 | 2019-08-22                  |\n| 6           | 2           | 2019-08-11 | 2019-08-13                  |\n| 7           | 4           | 2019-08-09 | 2019-08-09                  |\n+-------------+-------------+------------+-----------------------------+\n输出:\n+----------------------+\n| immediate_percentage |\n+----------------------+\n| 50.00                |\n+----------------------+\n解释:\n1 号顾客的 1 号订单是首次订单,并且是计划订单。\n2 号顾客的 2 号订单是首次订单,并且是即时订单。\n3 号顾客的 5 号订单是首次订单,并且是计划订单。\n4 号顾客的 7 号订单是首次订单,并且是即时订单。\n因此,一半顾客的首次订单是即时的。\n
\n", + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 77, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef immediate_food_delivery(delivery: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"22K\", \"totalSubmission\": \"39.6K\", \"totalAcceptedRaw\": 21982, \"totalSubmissionRaw\": 39576, \"acRate\": \"55.5%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Delivery\":[\"delivery_id\",\"customer_id\",\"order_date\",\"customer_pref_delivery_date\"]},\"rows\":{\"Delivery\":[[1,1,\"2019-08-01\",\"2019-08-02\"],[2,2,\"2019-08-02\",\"2019-08-02\"],[3,1,\"2019-08-11\",\"2019-08-12\"],[4,3,\"2019-08-24\",\"2019-08-24\"],[5,3,\"2019-08-21\",\"2019-08-22\"],[6,2,\"2019-08-11\",\"2019-08-13\"],[7,4,\"2019-08-09\",\"2019-08-09\"]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date)\"],\"mssql\":[\"Create table Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date)\"],\"oraclesql\":[\"Create table Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date)\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"],\"database\":true,\"name\":\"immediate_food_delivery\",\"pythondata\":[\"Delivery = pd.DataFrame([], columns=['delivery_id', 'customer_id', 'order_date', 'customer_pref_delivery_date']).astype({'delivery_id':'Int64', 'customer_id':'Int64', 'order_date':'datetime64[ns]', 'customer_pref_delivery_date':'datetime64[ns]'})\"],\"postgresql\":[\"\\nCreate table If Not Exists Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date)\"],\"database_schema\":{\"Delivery\":{\"delivery_id\":\"INT\",\"customer_id\":\"INT\",\"order_date\":\"DATE\",\"customer_pref_delivery_date\":\"DATE\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date)", + "Truncate table Delivery", + "insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('1', '1', '2019-08-01', '2019-08-02')", + "insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('2', '2', '2019-08-02', '2019-08-02')", + "insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('3', '1', '2019-08-11', '2019-08-12')", + "insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('4', '3', '2019-08-24', '2019-08-24')", + "insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('5', '3', '2019-08-21', '2019-08-22')", + "insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('6', '2', '2019-08-11', '2019-08-13')", + "insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('7', '4', '2019-08-09', '2019-08-09')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Delivery\":[\"delivery_id\",\"customer_id\",\"order_date\",\"customer_pref_delivery_date\"]},\"rows\":{\"Delivery\":[[1,1,\"2019-08-01\",\"2019-08-02\"],[2,2,\"2019-08-02\",\"2019-08-02\"],[3,1,\"2019-08-11\",\"2019-08-12\"],[4,3,\"2019-08-24\",\"2019-08-24\"],[5,3,\"2019-08-21\",\"2019-08-22\"],[6,2,\"2019-08-11\",\"2019-08-13\"],[7,4,\"2019-08-09\",\"2019-08-09\"]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/invalid-tweets.json b/leetcode-cn/originData/invalid-tweets.json new file mode 100644 index 00000000..123ebed8 --- /dev/null +++ b/leetcode-cn/originData/invalid-tweets.json @@ -0,0 +1,89 @@ +{ + "data": { + "question": { + "questionId": "1827", + "questionFrontendId": "1683", + "categoryTitle": "Database", + "boundTopicId": 517777, + "title": "Invalid Tweets", + "titleSlug": "invalid-tweets", + "content": "

Table: Tweets

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| tweet_id       | int     |\n| content        | varchar |\n+----------------+---------+\ntweet_id is the primary key (column with unique values) for this table.\nThis table contains all the tweets in a social media app.\n
\n\n

 

\n\n

Write a solution to find the IDs of the invalid tweets. The tweet is invalid if the number of characters used in the content of the tweet is strictly greater than 15.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nTweets table:\n+----------+----------------------------------+\n| tweet_id | content                          |\n+----------+----------------------------------+\n| 1        | Vote for Biden                   |\n| 2        | Let us make America great again! |\n+----------+----------------------------------+\nOutput: \n+----------+\n| tweet_id |\n+----------+\n| 2        |\n+----------+\nExplanation: \nTweet 1 has length = 14. It is a valid tweet.\nTweet 2 has length = 32. It is an invalid tweet.\n
\n", + "translatedTitle": "无效的推文", + "translatedContent": "

表:Tweets

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| tweet_id       | int     |\n| content        | varchar |\n+----------------+---------+\n在 SQL 中,tweet_id 是这个表的主键。\n这个表包含某社交媒体 App 中所有的推文。
\n\n

 

\n\n

查询所有无效推文的编号(ID)。当推文内容中的字符数严格大于 15 时,该推文是无效的。

\n\n

任意顺序返回结果表。

\n\n

查询结果格式如下所示:

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nTweets 表:\n+----------+----------------------------------+\n| tweet_id | content                          |\n+----------+----------------------------------+\n| 1        | Vote for Biden                   |\n| 2        | Let us make America great again! |\n+----------+----------------------------------+\n\n输出:\n+----------+\n| tweet_id |\n+----------+\n| 2        |\n+----------+\n解释:\n推文 1 的长度 length = 14。该推文是有效的。\n推文 2 的长度 length = 32。该推文是无效的。\n
\n", + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 51, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef invalid_tweets(tweets: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"39.7K\", \"totalSubmission\": \"46.8K\", \"totalAcceptedRaw\": 39746, \"totalSubmissionRaw\": 46800, \"acRate\": \"84.9%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Tweets\":[\"tweet_id\",\"content\"]},\"rows\":{\"Tweets\":[[1,\"Vote for Biden\"],[2,\"Let us make America great again!\"]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Tweets(tweet_id int, content varchar(50))\"],\"mssql\":[\"Create table Tweets(tweet_id int, content varchar(50))\"],\"oraclesql\":[\"Create table Tweets(tweet_id int, content varchar(50))\"],\"database\":true,\"name\":\"invalid_tweets\",\"pythondata\":[\"Tweets = pd.DataFrame([], columns=['tweet_id', 'content']).astype({'tweet_id':'Int64', 'content':'object'})\"],\"postgresql\":[\"Create table If Not Exists Tweets(tweet_id int, content varchar(50))\"],\"database_schema\":{\"Tweets\":{\"tweet_id\":\"INT\",\"content\":\"VARCHAR(50)\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Tweets(tweet_id int, content varchar(50))", + "Truncate table Tweets", + "insert into Tweets (tweet_id, content) values ('1', 'Vote for Biden')", + "insert into Tweets (tweet_id, content) values ('2', 'Let us make America great again!')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Tweets\":[\"tweet_id\",\"content\"]},\"rows\":{\"Tweets\":[[1,\"Vote for Biden\"],[2,\"Let us make America great again!\"]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/investments-in-2016.json b/leetcode-cn/originData/investments-in-2016.json new file mode 100644 index 00000000..10a72de1 --- /dev/null +++ b/leetcode-cn/originData/investments-in-2016.json @@ -0,0 +1,93 @@ +{ + "data": { + "question": { + "questionId": "585", + "questionFrontendId": "585", + "categoryTitle": "Database", + "boundTopicId": 2643, + "title": "Investments in 2016", + "titleSlug": "investments-in-2016", + "content": "

Table: Insurance

\n\n
\n+-------------+-------+\n| Column Name | Type  |\n+-------------+-------+\n| pid         | int   |\n| tiv_2015    | float |\n| tiv_2016    | float |\n| lat         | float |\n| lon         | float |\n+-------------+-------+\npid is the primary key (column with unique values) for this table.\nEach row of this table contains information about one policy where:\npid is the policyholder's policy ID.\ntiv_2015 is the total investment value in 2015 and tiv_2016 is the total investment value in 2016.\nlat is the latitude of the policy holder's city. It's guaranteed that lat is not NULL.\nlon is the longitude of the policy holder's city. It's guaranteed that lon is not NULL.\n
\n\n

 

\n\n

Write a solution to report the sum of all total investment values in 2016 tiv_2016, for all policyholders who:

\n\n
    \n\t
  • have the same tiv_2015 value as one or more other policyholders, and
  • \n\t
  • are not located in the same city as any other policyholder (i.e., the (lat, lon) attribute pairs must be unique).
  • \n
\n\n

Round tiv_2016 to two decimal places.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nInsurance table:\n+-----+----------+----------+-----+-----+\n| pid | tiv_2015 | tiv_2016 | lat | lon |\n+-----+----------+----------+-----+-----+\n| 1   | 10       | 5        | 10  | 10  |\n| 2   | 20       | 20       | 20  | 20  |\n| 3   | 10       | 30       | 20  | 20  |\n| 4   | 10       | 40       | 40  | 40  |\n+-----+----------+----------+-----+-----+\nOutput: \n+----------+\n| tiv_2016 |\n+----------+\n| 45.00    |\n+----------+\nExplanation: \nThe first record in the table, like the last record, meets both of the two criteria.\nThe tiv_2015 value 10 is the same as the third and fourth records, and its location is unique.\n\nThe second record does not meet any of the two criteria. Its tiv_2015 is not like any other policyholders and its location is the same as the third record, which makes the third record fail, too.\nSo, the result is the sum of tiv_2016 of the first and last record, which is 45.\n
\n", + "translatedTitle": "2016年的投资", + "translatedContent": "

Insurance 表:

\n\n
\n
\n
\n+-------------+-------+\n| Column Name | Type  |\n+-------------+-------+\n| pid         | int   |\n| tiv_2015    | float |\n| tiv_2016    | float |\n| lat         | float |\n| lon         | float |\n+-------------+-------+\npid 是这张表的主键(具有唯一值的列)。\n表中的每一行都包含一条保险信息,其中:\npid 是投保人的投保编号。\ntiv_2015 是该投保人在 2015 年的总投保金额,tiv_2016 是该投保人在 2016 年的总投保金额。\nlat 是投保人所在城市的纬度。题目数据确保 lat 不为空。\nlon 是投保人所在城市的经度。题目数据确保 lon 不为空。
\n\n

 

\n\n

编写解决方案报告 2016 年 (tiv_2016) 所有满足下述条件的投保人的投保金额之和:

\n\n
    \n\t
  • 他在 2015 年的投保额 (tiv_2015) 至少跟一个其他投保人在 2015 年的投保额相同。
  • \n\t
  • 他所在的城市必须与其他投保人都不同(也就是说 (lat, lon) 不能跟其他任何一个投保人完全相同)。
  • \n
\n\n

tiv_2016 四舍五入的 两位小数

\n\n

查询结果格式如下例所示。

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nInsurance 表:\n+-----+----------+----------+-----+-----+\n| pid | tiv_2015 | tiv_2016 | lat | lon |\n+-----+----------+----------+-----+-----+\n| 1   | 10       | 5        | 10  | 10  |\n| 2   | 20       | 20       | 20  | 20  |\n| 3   | 10       | 30       | 20  | 20  |\n| 4   | 10       | 40       | 40  | 40  |\n+-----+----------+----------+-----+-----+\n输出:\n+----------+\n| tiv_2016 |\n+----------+\n| 45.00    |\n+----------+\n解释:\n表中的第一条记录和最后一条记录都满足两个条件。\ntiv_2015 值为 10 与第三条和第四条记录相同,且其位置是唯一的。\n\n第二条记录不符合任何一个条件。其 tiv_2015 与其他投保人不同,并且位置与第三条记录相同,这也导致了第三条记录不符合题目要求。\n因此,结果是第一条记录和最后一条记录的 tiv_2016 之和,即 45 。
\n
\n
\n", + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 112, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef find_investments(insurance: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"28.8K\", \"totalSubmission\": \"61.9K\", \"totalAcceptedRaw\": 28808, \"totalSubmissionRaw\": 61853, \"acRate\": \"46.6%\"}", + "hints": [ + "Make the (LAT, LON) a pair to represent the location information" + ], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Insurance\":[\"pid\",\"tiv_2015\",\"tiv_2016\",\"lat\",\"lon\"]},\"rows\":{\"Insurance\":[[1,10,5,10,10],[2,20,20,20,20],[3,10,30,20,20],[4,10,40,40,40]]}}", + "metaData": "{\"mysql\":[\"Create Table If Not Exists Insurance (pid int, tiv_2015 float, tiv_2016 float, lat float, lon float)\"],\"mssql\":[\"Create Table Insurance (pid int, tiv_2015 float, tiv_2016 float, lat float, lon float)\"],\"oraclesql\":[\"Create Table Insurance (pid int, tiv_2015 float, tiv_2016 float, lat float, lon float)\"],\"database\":true,\"name\":\"find_investments\",\"pythondata\":[\"Insurance = pd.DataFrame([], columns=['pid', 'tiv_2015', 'tiv_2016', 'lat', 'lon']).astype({'pid':'Int64', 'tiv_2015':'Float64', 'tiv_2016':'Float64', 'lat':'Float64', 'lon':'Float64'})\"],\"postgresql\":[\"\\nCreate Table If Not Exists Insurance (pid int, tiv_2015 float, tiv_2016 float, lat float, lon float)\"],\"database_schema\":{\"Insurance\":{\"pid\":\"INT\",\"tiv_2015\":\"FLOAT\",\"tiv_2016\":\"FLOAT\",\"lat\":\"FLOAT\",\"lon\":\"FLOAT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create Table If Not Exists Insurance (pid int, tiv_2015 float, tiv_2016 float, lat float, lon float)", + "Truncate table Insurance", + "insert into Insurance (pid, tiv_2015, tiv_2016, lat, lon) values ('1', '10', '5', '10', '10')", + "insert into Insurance (pid, tiv_2015, tiv_2016, lat, lon) values ('2', '20', '20', '20', '20')", + "insert into Insurance (pid, tiv_2015, tiv_2016, lat, lon) values ('3', '10', '30', '20', '20')", + "insert into Insurance (pid, tiv_2015, tiv_2016, lat, lon) values ('4', '10', '40', '40', '40')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Insurance\":[\"pid\",\"tiv_2015\",\"tiv_2016\",\"lat\",\"lon\"]},\"rows\":{\"Insurance\":[[1,10,5,10,10],[2,20,20,20,20],[3,10,30,20,20],[4,10,40,40,40]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/last-person-to-fit-in-the-bus.json b/leetcode-cn/originData/last-person-to-fit-in-the-bus.json new file mode 100644 index 00000000..cea9a9f6 --- /dev/null +++ b/leetcode-cn/originData/last-person-to-fit-in-the-bus.json @@ -0,0 +1,93 @@ +{ + "data": { + "question": { + "questionId": "1327", + "questionFrontendId": "1204", + "categoryTitle": "Database", + "boundTopicId": 33152, + "title": "Last Person to Fit in the Bus", + "titleSlug": "last-person-to-fit-in-the-bus", + "content": "

Table: Queue

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| person_id   | int     |\n| person_name | varchar |\n| weight      | int     |\n| turn        | int     |\n+-------------+---------+\nperson_id column contains unique values.\nThis table has the information about all people waiting for a bus.\nThe person_id and turn columns will contain all numbers from 1 to n, where n is the number of rows in the table.\nturn determines the order of which the people will board the bus, where turn=1 denotes the first person to board and turn=n denotes the last person to board.\nweight is the weight of the person in kilograms.\n
\n\n

 

\n\n

There is a queue of people waiting to board a bus. However, the bus has a weight limit of 1000 kilograms, so there may be some people who cannot board.

\n\n

Write a solution to find the person_name of the last person that can fit on the bus without exceeding the weight limit. The test cases are generated such that the first person does not exceed the weight limit.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nQueue table:\n+-----------+-------------+--------+------+\n| person_id | person_name | weight | turn |\n+-----------+-------------+--------+------+\n| 5         | Alice       | 250    | 1    |\n| 4         | Bob         | 175    | 5    |\n| 3         | Alex        | 350    | 2    |\n| 6         | John Cena   | 400    | 3    |\n| 1         | Winston     | 500    | 6    |\n| 2         | Marie       | 200    | 4    |\n+-----------+-------------+--------+------+\nOutput: \n+-------------+\n| person_name |\n+-------------+\n| John Cena   |\n+-------------+\nExplanation: The folowing table is ordered by the turn for simplicity.\n+------+----+-----------+--------+--------------+\n| Turn | ID | Name      | Weight | Total Weight |\n+------+----+-----------+--------+--------------+\n| 1    | 5  | Alice     | 250    | 250          |\n| 2    | 3  | Alex      | 350    | 600          |\n| 3    | 6  | John Cena | 400    | 1000         | (last person to board)\n| 4    | 2  | Marie     | 200    | 1200         | (cannot board)\n| 5    | 4  | Bob       | 175    | ___          |\n| 6    | 1  | Winston   | 500    | ___          |\n+------+----+-----------+--------+--------------+\n
\n", + "translatedTitle": "最后一个能进入巴士的人", + "translatedContent": "

表: Queue

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| person_id   | int     |\n| person_name | varchar |\n| weight      | int     |\n| turn        | int     |\n+-------------+---------+\nperson_id 是这个表具有唯一值的列。\n该表展示了所有候车乘客的信息。\n表中 person_id 和 turn 列将包含从 1 到 n 的所有数字,其中 n 是表中的行数。\nturn 决定了候车乘客上巴士的顺序,其中 turn=1 表示第一个上巴士,turn=n 表示最后一个上巴士。\nweight 表示候车乘客的体重,以千克为单位。\n
\n\n

 

\n\n

有一队乘客在等着上巴士。然而,巴士有1000  千克 的重量限制,所以其中一部分乘客可能无法上巴士。

\n\n

编写解决方案找出 最后一个 上巴士且不超过重量限制的乘客,并报告 person_name 。题目测试用例确保顺位第一的人可以上巴士且不会超重。

\n\n

返回结果格式如下所示。

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nQueue 表\n+-----------+-------------+--------+------+\n| person_id | person_name | weight | turn |\n+-----------+-------------+--------+------+\n| 5         | Alice       | 250    | 1    |\n| 4         | Bob         | 175    | 5    |\n| 3         | Alex        | 350    | 2    |\n| 6         | John Cena   | 400    | 3    |\n| 1         | Winston     | 500    | 6    |\n| 2         | Marie       | 200    | 4    |\n+-----------+-------------+--------+------+\n输出:\n+-------------+\n| person_name |\n+-------------+\n| John Cena   |\n+-------------+\n解释:\n为了简化,Queue 表按 turn 列由小到大排序。\n+------+----+-----------+--------+--------------+\n| Turn | ID | Name      | Weight | Total Weight |\n+------+----+-----------+--------+--------------+\n| 1    | 5  | Alice     | 250    | 250          |\n| 2    | 3  | Alex      | 350    | 600          |\n| 3    | 6  | John Cena | 400    | 1000         | (最后一个上巴士)\n| 4    | 2  | Marie     | 200    | 1200         | (无法上巴士)\n| 5    | 4  | Bob       | 175    | ___          |\n| 6    | 1  | Winston   | 500    | ___          |\n+------+----+-----------+--------+--------------+
\n", + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 102, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef last_passenger(queue: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"20.1K\", \"totalSubmission\": \"28.4K\", \"totalAcceptedRaw\": 20111, \"totalSubmissionRaw\": 28363, \"acRate\": \"70.9%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Queue\":[\"person_id\",\"person_name\",\"weight\",\"turn\"]},\"rows\":{\"Queue\":[[5,\"Alice\",250,1],[4,\"Bob\",175,5],[3,\"Alex\",350,2],[6,\"John Cena\",400,3],[1,\"Winston\",500,6],[2,\"Marie\",200,4]]}}", + "metaData": "{\"manual\":false,\"mysql\":[\"Create table If Not Exists Queue (person_id int, person_name varchar(30), weight int, turn int)\"],\"mssql\":[\"Create table Queue (person_id int, person_name varchar(30), weight int, turn int)\"],\"oraclesql\":[\"Create table Queue (person_id int, person_name varchar(30), weight int, turn int)\"],\"database\":true,\"name\":\"last_passenger\",\"pythondata\":[\"Queue = pd.DataFrame([], columns=['person_id', 'person_name', 'weight', 'turn']).astype({'person_id':'Int64', 'person_name':'object', 'weight':'Int64', 'turn':'Int64'})\"],\"postgresql\":[\"\\nCreate table If Not Exists Queue (person_id int, person_name varchar(30), weight int, turn int)\"],\"database_schema\":{\"Queue\":{\"person_id\":\"INT\",\"person_name\":\"VARCHAR(30)\",\"weight\":\"INT\",\"turn\":\"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Queue (person_id int, person_name varchar(30), weight int, turn int)", + "Truncate table Queue", + "insert into Queue (person_id, person_name, weight, turn) values ('5', 'Alice', '250', '1')", + "insert into Queue (person_id, person_name, weight, turn) values ('4', 'Bob', '175', '5')", + "insert into Queue (person_id, person_name, weight, turn) values ('3', 'Alex', '350', '2')", + "insert into Queue (person_id, person_name, weight, turn) values ('6', 'John Cena', '400', '3')", + "insert into Queue (person_id, person_name, weight, turn) values ('1', 'Winston', '500', '6')", + "insert into Queue (person_id, person_name, weight, turn) values ('2', 'Marie', '200', '4')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Queue\":[\"person_id\",\"person_name\",\"weight\",\"turn\"]},\"rows\":{\"Queue\":[[5,\"Alice\",250,1],[4,\"Bob\",175,5],[3,\"Alex\",350,2],[6,\"John Cena\",400,3],[1,\"Winston\",500,6],[2,\"Marie\",200,4]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/lexicographically-smallest-equivalent-string.json b/leetcode-cn/originData/lexicographically-smallest-equivalent-string.json new file mode 100644 index 00000000..81491836 --- /dev/null +++ b/leetcode-cn/originData/lexicographically-smallest-equivalent-string.json @@ -0,0 +1,178 @@ +{ + "data": { + "question": { + "questionId": "1058", + "questionFrontendId": "1061", + "categoryTitle": "Algorithms", + "boundTopicId": 3302, + "title": "Lexicographically Smallest Equivalent String", + "titleSlug": "lexicographically-smallest-equivalent-string", + "content": "

You are given two strings of the same length s1 and s2 and a string baseStr.

\n\n

We say s1[i] and s2[i] are equivalent characters.

\n\n
    \n\t
  • For example, if s1 = "abc" and s2 = "cde", then we have 'a' == 'c', 'b' == 'd', and 'c' == 'e'.
  • \n
\n\n

Equivalent characters follow the usual rules of any equivalence relation:

\n\n
    \n\t
  • Reflexivity: 'a' == 'a'.
  • \n\t
  • Symmetry: 'a' == 'b' implies 'b' == 'a'.
  • \n\t
  • Transitivity: 'a' == 'b' and 'b' == 'c' implies 'a' == 'c'.
  • \n
\n\n

For example, given the equivalency information from s1 = "abc" and s2 = "cde", "acd" and "aab" are equivalent strings of baseStr = "eed", and "aab" is the lexicographically smallest equivalent string of baseStr.

\n\n

Return the lexicographically smallest equivalent string of baseStr by using the equivalency information from s1 and s2.

\n\n

 

\n

Example 1:

\n\n
\nInput: s1 = "parker", s2 = "morris", baseStr = "parser"\nOutput: "makkek"\nExplanation: Based on the equivalency information in s1 and s2, we can group their characters as [m,p], [a,o], [k,r,s], [e,i].\nThe characters in each group are equivalent and sorted in lexicographical order.\nSo the answer is "makkek".\n
\n\n

Example 2:

\n\n
\nInput: s1 = "hello", s2 = "world", baseStr = "hold"\nOutput: "hdld"\nExplanation: Based on the equivalency information in s1 and s2, we can group their characters as [h,w], [d,e,o], [l,r].\nSo only the second letter 'o' in baseStr is changed to 'd', the answer is "hdld".\n
\n\n

Example 3:

\n\n
\nInput: s1 = "leetcode", s2 = "programs", baseStr = "sourcecode"\nOutput: "aauaaaaada"\nExplanation: We group the equivalent characters in s1 and s2 as [a,o,e,r,s,c], [l,p], [g,t] and [d,m], thus all letters in baseStr except 'u' and 'd' are transformed to 'a', the answer is "aauaaaaada".\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s1.length, s2.length, baseStr <= 1000
  • \n\t
  • s1.length == s2.length
  • \n\t
  • s1, s2, and baseStr consist of lowercase English letters.
  • \n
\n", + "translatedTitle": "按字典序排列最小的等效字符串", + "translatedContent": "

给出长度相同的两个字符串s1 和 s2 ,还有一个字符串 baseStr 。

\n\n

其中  s1[i] 和 s2[i]  是一组等价字符。

\n\n
    \n\t
  • 举个例子,如果 s1 = \"abc\" 且 s2 = \"cde\",那么就有 'a' == 'c', 'b' == 'd', 'c' == 'e'
  • \n
\n\n

等价字符遵循任何等价关系的一般规则:

\n\n
    \n\t
  •  自反性 'a' == 'a'
  • \n\t
  •  对称性 'a' == 'b' 则必定有 'b' == 'a'
  • \n\t
  •  传递性'a' == 'b''b' == 'c' 就表明 'a' == 'c'
  • \n
\n\n

例如, s1 = \"abc\" 和 s2 = \"cde\" 的等价信息和之前的例子一样,那么 baseStr = \"eed\" , \"acd\" 或 \"aab\",这三个字符串都是等价的,而 \"aab\" 是 baseStr 的按字典序最小的等价字符串

\n\n

利用 s1 和 s2 的等价信息,找出并返回 baseStr 的按字典序排列最小的等价字符串。

\n\n

 

\n\n

示例 1:

\n\n
\n输入:s1 = \"parker\", s2 = \"morris\", baseStr = \"parser\"\n输出:\"makkek\"\n解释:根据 AB 中的等价信息,我们可以将这些字符分为 [m,p], [a,o], [k,r,s], [e,i] 共 4 组。每组中的字符都是等价的,并按字典序排列。所以答案是 \"makkek\"。\n
\n\n

示例 2:

\n\n
\n输入:s1 = \"hello\", s2 = \"world\", baseStr = \"hold\"\n输出:\"hdld\"\n解释:根据 AB 中的等价信息,我们可以将这些字符分为 [h,w], [d,e,o], [l,r] 共 3 组。所以只有 S 中的第二个字符 'o' 变成 'd',最后答案为 \"hdld\"。\n
\n\n

示例 3:

\n\n
\n输入:s1 = \"leetcode\", s2 = \"programs\", baseStr = \"sourcecode\"\n输出:\"aauaaaaada\"\n解释:我们可以把 A 和 B 中的等价字符分为 [a,o,e,r,s,c], [l,p], [g,t][d,m] 共 4 组,因此 S 中除了 'u''d' 之外的所有字母都转化成了 'a',最后答案为 \"aauaaaaada\"。\n
\n\n

 

\n\n

提示:

\n\n
    \n\t
  • 1 <= s1.length, s2.length, baseStr <= 1000
  • \n\t
  • s1.length == s2.length
  • \n\t
  • 字符串s1s2, and baseStr 仅由从 'a' 到 'z' 的小写英文字母组成。
  • \n
\n", + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 37, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": true, \"java\": true, \"python\": true, \"python3\": true, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Union Find", + "slug": "union-find", + "translatedName": "并查集", + "__typename": "TopicTagNode" + }, + { + "name": "String", + "slug": "string", + "translatedName": "字符串", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "C++", + "langSlug": "cpp", + "code": "class Solution {\npublic:\n string smallestEquivalentString(string s1, string s2, string baseStr) {\n\n }\n};", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Java", + "langSlug": "java", + "code": "class Solution {\n public String smallestEquivalentString(String s1, String s2, String baseStr) {\n\n }\n}", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Python", + "langSlug": "python", + "code": "class Solution(object):\n def smallestEquivalentString(self, s1, s2, baseStr):\n \"\"\"\n :type s1: str\n :type s2: str\n :type baseStr: str\n :rtype: str\n \"\"\"", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Python3", + "langSlug": "python3", + "code": "class Solution:\n def smallestEquivalentString(self, s1: str, s2: str, baseStr: str) -> str:", + "__typename": "CodeSnippetNode" + }, + { + "lang": "C", + "langSlug": "c", + "code": "char* smallestEquivalentString(char* s1, char* s2, char* baseStr) {\n \n}", + "__typename": "CodeSnippetNode" + }, + { + "lang": "C#", + "langSlug": "csharp", + "code": "public class Solution {\n public string SmallestEquivalentString(string s1, string s2, string baseStr) {\n\n }\n}", + "__typename": "CodeSnippetNode" + }, + { + "lang": "JavaScript", + "langSlug": "javascript", + "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @param {string} baseStr\n * @return {string}\n */\nvar smallestEquivalentString = function(s1, s2, baseStr) {\n\n};", + "__typename": "CodeSnippetNode" + }, + { + "lang": "TypeScript", + "langSlug": "typescript", + "code": "function smallestEquivalentString(s1: string, s2: string, baseStr: string): string {\n \n};", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PHP", + "langSlug": "php", + "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @param String $baseStr\n * @return String\n */\n function smallestEquivalentString($s1, $s2, $baseStr) {\n\n }\n}", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Swift", + "langSlug": "swift", + "code": "class Solution {\n func smallestEquivalentString(_ s1: String, _ s2: String, _ baseStr: String) -> String {\n\n }\n}", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Kotlin", + "langSlug": "kotlin", + "code": "class Solution {\n fun smallestEquivalentString(s1: String, s2: String, baseStr: String): String {\n\n }\n}", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Dart", + "langSlug": "dart", + "code": "class Solution {\n String smallestEquivalentString(String s1, String s2, String baseStr) {\n \n }\n}", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Go", + "langSlug": "golang", + "code": "func smallestEquivalentString(s1 string, s2 string, baseStr string) string {\n\n}", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Ruby", + "langSlug": "ruby", + "code": "# @param {String} s1\n# @param {String} s2\n# @param {String} base_str\n# @return {String}\ndef smallest_equivalent_string(s1, s2, base_str)\n\nend", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Scala", + "langSlug": "scala", + "code": "object Solution {\n def smallestEquivalentString(s1: String, s2: String, baseStr: String): String = {\n\n }\n}", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Rust", + "langSlug": "rust", + "code": "impl Solution {\n pub fn smallest_equivalent_string(s1: String, s2: String, base_str: String) -> String {\n\n }\n}", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Racket", + "langSlug": "racket", + "code": "(define/contract (smallest-equivalent-string s1 s2 baseStr)\n (-> string? string? string? string?)\n )", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Erlang", + "langSlug": "erlang", + "code": "-spec smallest_equivalent_string(S1 :: unicode:unicode_binary(), S2 :: unicode:unicode_binary(), BaseStr :: unicode:unicode_binary()) -> unicode:unicode_binary().\nsmallest_equivalent_string(S1, S2, BaseStr) ->\n .", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Elixir", + "langSlug": "elixir", + "code": "defmodule Solution do\n @spec smallest_equivalent_string(s1 :: String.t, s2 :: String.t, base_str :: String.t) :: String.t\n def smallest_equivalent_string(s1, s2, base_str) do\n \n end\nend", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"6.2K\", \"totalSubmission\": \"9.5K\", \"totalAcceptedRaw\": 6164, \"totalSubmissionRaw\": 9463, \"acRate\": \"65.1%\"}", + "hints": [ + "Model these equalities as edges of a graph.", + "Group each connected component of the graph and assign each node of this component to the node with the lowest lexicographically character.", + "Finally convert the string with the precalculated information." + ], + "solution": null, + "status": null, + "sampleTestCase": "\"parker\"\n\"morris\"\n\"parser\"", + "metaData": "{\n \"name\": \"smallestEquivalentString\",\n \"params\": [\n {\n \"name\": \"s1\",\n \"type\": \"string\"\n },\n {\n \"name\": \"s2\",\n \"type\": \"string\"\n },\n {\n \"name\": \"baseStr\",\n \"type\": \"string\"\n }\n ],\n \"return\": {\n \"type\": \"string\"\n }\n}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [], + "enableRunCode": true, + "envInfo": "{\"cpp\":[\"C++\",\"

\\u7248\\u672c\\uff1aclang 11<\\/code> \\u91c7\\u7528\\u6700\\u65b0C++ 20\\u6807\\u51c6\\u3002<\\/p>\\r\\n\\r\\n

\\u7f16\\u8bd1\\u65f6\\uff0c\\u5c06\\u4f1a\\u91c7\\u7528-O2<\\/code>\\u7ea7\\u4f18\\u5316\\u3002AddressSanitizer<\\/a> \\u4e5f\\u88ab\\u5f00\\u542f\\u6765\\u68c0\\u6d4bout-of-bounds<\\/code>\\u548cuse-after-free<\\/code>\\u9519\\u8bef\\u3002<\\/p>\\r\\n\\r\\n

\\u4e3a\\u4e86\\u4f7f\\u7528\\u65b9\\u4fbf\\uff0c\\u5927\\u90e8\\u5206\\u6807\\u51c6\\u5e93\\u7684\\u5934\\u6587\\u4ef6\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8\\u5bfc\\u5165\\u3002<\\/p>\"],\"java\":[\"Java\",\"

\\u7248\\u672c\\uff1aOpenJDK 17<\\/code>\\u3002\\u53ef\\u4ee5\\u4f7f\\u7528Java 8\\u7684\\u7279\\u6027\\u4f8b\\u5982\\uff0clambda expressions \\u548c stream API\\u3002<\\/p>\\r\\n\\r\\n

\\u4e3a\\u4e86\\u65b9\\u4fbf\\u8d77\\u89c1\\uff0c\\u5927\\u90e8\\u5206\\u6807\\u51c6\\u5e93\\u7684\\u5934\\u6587\\u4ef6\\u5df2\\u88ab\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n

\\u5305\\u542b Pair \\u7c7b: https:\\/\\/docs.oracle.com\\/javase\\/8\\/javafx\\/api\\/javafx\\/util\\/Pair.html <\\/p>\"],\"python\":[\"Python\",\"

\\u7248\\u672c\\uff1a Python 2.7.12<\\/code><\\/p>\\r\\n\\r\\n

\\u4e3a\\u4e86\\u65b9\\u4fbf\\u8d77\\u89c1\\uff0c\\u5927\\u90e8\\u5206\\u5e38\\u7528\\u5e93\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8 \\u5bfc\\u5165\\uff0c\\u5982\\uff1aarray<\\/a>, bisect<\\/a>, collections<\\/a>\\u3002\\u5982\\u679c\\u60a8\\u9700\\u8981\\u4f7f\\u7528\\u5176\\u4ed6\\u5e93\\u51fd\\u6570\\uff0c\\u8bf7\\u81ea\\u884c\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n

\\u6ce8\\u610f Python 2.7 \\u5c06\\u57282020\\u5e74\\u540e\\u4e0d\\u518d\\u7ef4\\u62a4<\\/a>\\u3002 \\u5982\\u60f3\\u4f7f\\u7528\\u6700\\u65b0\\u7248\\u7684Python\\uff0c\\u8bf7\\u9009\\u62e9Python 3\\u3002<\\/p>\"],\"c\":[\"C\",\"

\\u7248\\u672c\\uff1aGCC 8.2<\\/code>\\uff0c\\u91c7\\u7528GNU11\\u6807\\u51c6\\u3002<\\/p>\\r\\n\\r\\n

\\u7f16\\u8bd1\\u65f6\\uff0c\\u5c06\\u4f1a\\u91c7\\u7528-O1<\\/code>\\u7ea7\\u4f18\\u5316\\u3002 AddressSanitizer<\\/a>\\u4e5f\\u88ab\\u5f00\\u542f\\u6765\\u68c0\\u6d4bout-of-bounds<\\/code>\\u548cuse-after-free<\\/code>\\u9519\\u8bef\\u3002<\\/p>\\r\\n\\r\\n

\\u4e3a\\u4e86\\u4f7f\\u7528\\u65b9\\u4fbf\\uff0c\\u5927\\u90e8\\u5206\\u6807\\u51c6\\u5e93\\u7684\\u5934\\u6587\\u4ef6\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n

\\u5982\\u60f3\\u4f7f\\u7528\\u54c8\\u5e0c\\u8868\\u8fd0\\u7b97, \\u60a8\\u53ef\\u4ee5\\u4f7f\\u7528 uthash<\\/a>\\u3002 \\\"uthash.h\\\"\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5bfc\\u5165\\u3002\\u8bf7\\u770b\\u5982\\u4e0b\\u793a\\u4f8b:<\\/p>\\r\\n\\r\\n

1. \\u5f80\\u54c8\\u5e0c\\u8868\\u4e2d\\u6dfb\\u52a0\\u4e00\\u4e2a\\u5bf9\\u8c61\\uff1a<\\/b>\\r\\n

\\r\\nstruct hash_entry {\\r\\n    int id;            \\/* we'll use this field as the key *\\/\\r\\n    char name[10];\\r\\n    UT_hash_handle hh; \\/* makes this structure hashable *\\/\\r\\n};\\r\\n\\r\\nstruct hash_entry *users = NULL;\\r\\n\\r\\nvoid add_user(struct hash_entry *s) {\\r\\n    HASH_ADD_INT(users, id, s);\\r\\n}\\r\\n<\\/pre>\\r\\n<\\/p>\\r\\n\\r\\n

2. \\u5728\\u54c8\\u5e0c\\u8868\\u4e2d\\u67e5\\u627e\\u4e00\\u4e2a\\u5bf9\\u8c61\\uff1a<\\/b>\\r\\n

\\r\\nstruct hash_entry *find_user(int user_id) {\\r\\n    struct hash_entry *s;\\r\\n    HASH_FIND_INT(users, &user_id, s);\\r\\n    return s;\\r\\n}\\r\\n<\\/pre>\\r\\n<\\/p>\\r\\n\\r\\n

3. \\u4ece\\u54c8\\u5e0c\\u8868\\u4e2d\\u5220\\u9664\\u4e00\\u4e2a\\u5bf9\\u8c61\\uff1a<\\/b>\\r\\n

\\r\\nvoid delete_user(struct hash_entry *user) {\\r\\n    HASH_DEL(users, user);  \\r\\n}\\r\\n<\\/pre>\\r\\n<\\/p>\"],\"csharp\":[\"C#\",\"

C# 10<\\/a> \\u8fd0\\u884c\\u5728 .NET 6 \\u4e0a<\\/p>\"],\"javascript\":[\"JavaScript\",\"

\\u7248\\u672c\\uff1aNode.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n

\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a --harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f \\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n

lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n

\\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"ruby\":[\"Ruby\",\"

\\u4f7f\\u7528Ruby 3.1<\\/code>\\u6267\\u884c<\\/p>\\r\\n\\r\\n

\\u4e00\\u4e9b\\u5e38\\u7528\\u7684\\u6570\\u636e\\u7ed3\\u6784\\u5df2\\u5728 Algorithms \\u6a21\\u5757\\u4e2d\\u63d0\\u4f9b\\uff1ahttps:\\/\\/www.rubydoc.info\\/github\\/kanwei\\/algorithms\\/Algorithms<\\/p>\"],\"swift\":[\"Swift\",\"

\\u7248\\u672c\\uff1aSwift 5.5.2<\\/code><\\/p>\\r\\n\\r\\n

\\u6211\\u4eec\\u901a\\u5e38\\u4fdd\\u8bc1\\u66f4\\u65b0\\u5230 Apple\\u653e\\u51fa\\u7684\\u6700\\u65b0\\u7248Swift<\\/a>\\u3002\\u5982\\u679c\\u60a8\\u53d1\\u73b0Swift\\u4e0d\\u662f\\u6700\\u65b0\\u7248\\u7684\\uff0c\\u8bf7\\u8054\\u7cfb\\u6211\\u4eec\\uff01\\u6211\\u4eec\\u5c06\\u5c3d\\u5feb\\u66f4\\u65b0\\u3002<\\/p>\"],\"golang\":[\"Go\",\"

\\u7248\\u672c\\uff1aGo 1.21<\\/code><\\/p>\\r\\n\\r\\n

\\u652f\\u6301 https:\\/\\/godoc.org\\/github.com\\/emirpasic\\/gods@v1.18.1<\\/a> \\u7b2c\\u4e09\\u65b9\\u5e93\\u3002<\\/p>\"],\"python3\":[\"Python3\",\"

\\u7248\\u672c\\uff1aPython 3.10<\\/code><\\/p>\\r\\n\\r\\n

\\u4e3a\\u4e86\\u65b9\\u4fbf\\u8d77\\u89c1\\uff0c\\u5927\\u90e8\\u5206\\u5e38\\u7528\\u5e93\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8 \\u5bfc\\u5165\\uff0c\\u5982array<\\/a>, bisect<\\/a>, collections<\\/a>\\u3002 \\u5982\\u679c\\u60a8\\u9700\\u8981\\u4f7f\\u7528\\u5176\\u4ed6\\u5e93\\u51fd\\u6570\\uff0c\\u8bf7\\u81ea\\u884c\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n

\\u5982\\u9700\\u4f7f\\u7528 Map\\/TreeMap \\u6570\\u636e\\u7ed3\\u6784\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 sortedcontainers<\\/a> \\u5e93\\u3002<\\/p>\"],\"scala\":[\"Scala\",\"

\\u7248\\u672c\\uff1aScala 2.13<\\/code><\\/p>\"],\"kotlin\":[\"Kotlin\",\"

\\u7248\\u672c\\uff1aKotlin 1.9.0<\\/code><\\/p>\\r\\n\\r\\n

\\u6211\\u4eec\\u4f7f\\u7528\\u7684\\u662f JetBrains \\u63d0\\u4f9b\\u7684 experimental compiler\\u3002\\u5982\\u679c\\u60a8\\u8ba4\\u4e3a\\u60a8\\u9047\\u5230\\u4e86\\u7f16\\u8bd1\\u5668\\u76f8\\u5173\\u7684\\u95ee\\u9898\\uff0c\\u8bf7\\u5411\\u6211\\u4eec\\u53cd\\u9988<\\/p>\"],\"rust\":[\"Rust\",\"

\\u7248\\u672c\\uff1arust 1.58.1<\\/code><\\/p>\\r\\n\\r\\n

\\u652f\\u6301 crates.io \\u7684 rand<\\/a><\\/p>\"],\"php\":[\"PHP\",\"

PHP 8.1<\\/code>.<\\/p>\\r\\n\\r\\n

With bcmath module.<\\/p>\"],\"typescript\":[\"TypeScript\",\"

TypeScript 5.1.6<\\/p>\\r\\n\\r\\n

Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/p>\\r\\n\\r\\n

lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n

\\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"racket\":[\"Racket\",\"

Racket CS<\\/a> v8.3<\\/p>\\r\\n\\r\\n

\\u4f7f\\u7528 #lang racket<\\/p>\\r\\n\\r\\n

\\u5df2\\u9884\\u5148 (require data\\/gvector data\\/queue data\\/order data\\/heap). \\u82e5\\u9700\\u4f7f\\u7528\\u5176\\u5b83\\u6570\\u636e\\u7ed3\\u6784\\uff0c\\u53ef\\u81ea\\u884c require\\u3002<\\/p>\"],\"erlang\":[\"Erlang\",\"Erlang\\/OTP 24.2\"],\"elixir\":[\"Elixir\",\"Elixir 1.13.0 with Erlang\\/OTP 24.2\"],\"dart\":[\"Dart\",\"

Dart 2.17.3<\\/p>\\r\\n\\r\\n

\\u60a8\\u7684\\u4ee3\\u7801\\u5c06\\u4f1a\\u88ab\\u4e0d\\u7f16\\u8bd1\\u76f4\\u63a5\\u8fd0\\u884c<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "\"parker\"\n\"morris\"\n\"parser\"\n\"hello\"\n\"world\"\n\"hold\"\n\"leetcode\"\n\"programs\"\n\"sourcecode\"", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/list-the-products-ordered-in-a-period.json b/leetcode-cn/originData/list-the-products-ordered-in-a-period.json new file mode 100644 index 00000000..489cecb4 --- /dev/null +++ b/leetcode-cn/originData/list-the-products-ordered-in-a-period.json @@ -0,0 +1,106 @@ +{ + "data": { + "question": { + "questionId": "1462", + "questionFrontendId": "1327", + "categoryTitle": "Database", + "boundTopicId": 79635, + "title": "List the Products Ordered in a Period", + "titleSlug": "list-the-products-ordered-in-a-period", + "content": "

Table: Products

\n\n
\n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| product_id       | int     |\n| product_name     | varchar |\n| product_category | varchar |\n+------------------+---------+\nproduct_id is the primary key (column with unique values) for this table.\nThis table contains data about the company's products.\n
\n\n

 

\n\n

Table: Orders

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| order_date    | date    |\n| unit          | int     |\n+---------------+---------+\nThis table may have duplicate rows.\nproduct_id is a foreign key (reference column) to the Products table.\nunit is the number of products ordered in order_date.\n
\n\n

 

\n\n

Write a solution to get the names of products that have at least 100 units ordered in February 2020 and their amount.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nProducts table:\n+-------------+-----------------------+------------------+\n| product_id  | product_name          | product_category |\n+-------------+-----------------------+------------------+\n| 1           | Leetcode Solutions    | Book             |\n| 2           | Jewels of Stringology | Book             |\n| 3           | HP                    | Laptop           |\n| 4           | Lenovo                | Laptop           |\n| 5           | Leetcode Kit          | T-shirt          |\n+-------------+-----------------------+------------------+\nOrders table:\n+--------------+--------------+----------+\n| product_id   | order_date   | unit     |\n+--------------+--------------+----------+\n| 1            | 2020-02-05   | 60       |\n| 1            | 2020-02-10   | 70       |\n| 2            | 2020-01-18   | 30       |\n| 2            | 2020-02-11   | 80       |\n| 3            | 2020-02-17   | 2        |\n| 3            | 2020-02-24   | 3        |\n| 4            | 2020-03-01   | 20       |\n| 4            | 2020-03-04   | 30       |\n| 4            | 2020-03-04   | 60       |\n| 5            | 2020-02-25   | 50       |\n| 5            | 2020-02-27   | 50       |\n| 5            | 2020-03-01   | 50       |\n+--------------+--------------+----------+\nOutput: \n+--------------------+---------+\n| product_name       | unit    |\n+--------------------+---------+\n| Leetcode Solutions | 130     |\n| Leetcode Kit       | 100     |\n+--------------------+---------+\nExplanation: \nProducts with product_id = 1 is ordered in February a total of (60 + 70) = 130.\nProducts with product_id = 2 is ordered in February a total of 80.\nProducts with product_id = 3 is ordered in February a total of (2 + 3) = 5.\nProducts with product_id = 4 was not ordered in February 2020.\nProducts with product_id = 5 is ordered in February a total of (50 + 50) = 100.\n
\n", + "translatedTitle": "列出指定时间段内所有的下单产品", + "translatedContent": "

表: Products

\n\n
\n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| product_id       | int     |\n| product_name     | varchar |\n| product_category | varchar |\n+------------------+---------+\nproduct_id 是该表主键(具有唯一值的列)。\n该表包含该公司产品的数据。\n
\n\n

 

\n\n

表: Orders

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| order_date    | date    |\n| unit          | int     |\n+---------------+---------+\n该表可能包含重复行。\nproduct_id 是表单 Products 的外键(reference 列)。\nunit 是在日期 order_date 内下单产品的数目。\n
\n\n

 

\n\n

写一个解决方案,要求获取在 2020 年 2 月份下单的数量不少于 100 的产品的名字和数目。

\n\n

返回结果表单的 顺序无要求

\n\n

查询结果的格式如下。

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nProducts 表:\n+-------------+-----------------------+------------------+\n| product_id  | product_name          | product_category |\n+-------------+-----------------------+------------------+\n| 1           | Leetcode Solutions    | Book             |\n| 2           | Jewels of Stringology | Book             |\n| 3           | HP                    | Laptop           |\n| 4           | Lenovo                | Laptop           |\n| 5           | Leetcode Kit          | T-shirt          |\n+-------------+-----------------------+------------------+\nOrders 表:\n+--------------+--------------+----------+\n| product_id   | order_date   | unit     |\n+--------------+--------------+----------+\n| 1            | 2020-02-05   | 60       |\n| 1            | 2020-02-10   | 70       |\n| 2            | 2020-01-18   | 30       |\n| 2            | 2020-02-11   | 80       |\n| 3            | 2020-02-17   | 2        |\n| 3            | 2020-02-24   | 3        |\n| 4            | 2020-03-01   | 20       |\n| 4            | 2020-03-04   | 30       |\n| 4            | 2020-03-04   | 60       |\n| 5            | 2020-02-25   | 50       |\n| 5            | 2020-02-27   | 50       |\n| 5            | 2020-03-01   | 50       |\n+--------------+--------------+----------+\n输出:\n+--------------------+---------+\n| product_name       | unit    |\n+--------------------+---------+\n| Leetcode Solutions | 130     |\n| Leetcode Kit       | 100     |\n+--------------------+---------+\n解释:\n2020 年 2 月份下单 product_id = 1 的产品的数目总和为 (60 + 70) = 130 。\n2020 年 2 月份下单 product_id = 2 的产品的数目总和为 80 。\n2020 年 2 月份下单 product_id = 3 的产品的数目总和为 (2 + 3) = 5 。\n2020 年 2 月份 product_id = 4 的产品并没有下单。\n2020 年 2 月份下单 product_id = 5 的产品的数目总和为 (50 + 50) = 100 。
\n", + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 37, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef list_products(products: pd.DataFrame, orders: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"19.1K\", \"totalSubmission\": \"27.9K\", \"totalAcceptedRaw\": 19073, \"totalSubmissionRaw\": 27941, \"acRate\": \"68.3%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\": {\"Products\": [\"product_id\", \"product_name\", \"product_category\"], \"Orders\": [\"product_id\", \"order_date\", \"unit\"]}, \"rows\": {\"Products\": [[1, \"Leetcode Solutions\", \"Book\"], [2, \"Jewels of Stringology\", \"Book\"], [3, \"HP\", \"Laptop\"], [4, \"Lenovo\", \"Laptop\"], [5, \"Leetcode Kit\", \"T-shirt\"]], \"Orders\": [[1, \"2020-02-05\", 60], [1, \"2020-02-10\", 70], [2, \"2020-01-18\", 30], [2, \"2020-02-11\", 80], [3, \"2020-02-17\", 2], [3, \"2020-02-24\", 3], [4, \"2020-03-01\", 20], [4, \"2020-03-04\", 30], [4, \"2020-03-04\", 60], [5, \"2020-02-25\", 50], [5, \"2020-02-27\", 50], [5, \"2020-03-01\", 50]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Products (product_id int, product_name varchar(40), product_category varchar(40))\",\"Create table If Not Exists Orders (product_id int, order_date date, unit int)\"],\"mssql\":[\"Create table Products (product_id int, product_name varchar(40), product_category varchar(40))\\n\",\"Create table Orders (product_id int, order_date date, unit int)\"],\"oraclesql\":[\"Create table Products (product_id int, product_name varchar(40), product_category varchar(40))\",\"Create table Orders (product_id int, order_date date, unit int)\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"],\"database\":true,\"name\":\"list_products\",\"pythondata\":[\"Products = pd.DataFrame([], columns=['product_id', 'product_name', 'product_category']).astype({'product_id':'Int64', 'product_name':'object', 'product_category':'object'})\",\"Orders = pd.DataFrame([], columns=['product_id', 'order_date', 'unit']).astype({'product_id':'Int64', 'order_date':'datetime64[ns]', 'unit':'Int64'})\"],\"postgresql\":[\"\\nCreate table If Not Exists Products (product_id int, product_name varchar(40), product_category varchar(40))\",\"Create table If Not Exists Orders (product_id int, order_date date, unit int)\"],\"database_schema\":{\"Products\":{\"product_id\":\"INT\",\"product_name\":\"VARCHAR(40)\",\"product_category\":\"VARCHAR(40)\"},\"Orders\":{\"product_id\":\"INT\",\"order_date\":\"DATE\",\"unit\":\"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Products (product_id int, product_name varchar(40), product_category varchar(40))", + "Create table If Not Exists Orders (product_id int, order_date date, unit int)", + "Truncate table Products", + "insert into Products (product_id, product_name, product_category) values ('1', 'Leetcode Solutions', 'Book')", + "insert into Products (product_id, product_name, product_category) values ('2', 'Jewels of Stringology', 'Book')", + "insert into Products (product_id, product_name, product_category) values ('3', 'HP', 'Laptop')", + "insert into Products (product_id, product_name, product_category) values ('4', 'Lenovo', 'Laptop')", + "insert into Products (product_id, product_name, product_category) values ('5', 'Leetcode Kit', 'T-shirt')", + "Truncate table Orders", + "insert into Orders (product_id, order_date, unit) values ('1', '2020-02-05', '60')", + "insert into Orders (product_id, order_date, unit) values ('1', '2020-02-10', '70')", + "insert into Orders (product_id, order_date, unit) values ('2', '2020-01-18', '30')", + "insert into Orders (product_id, order_date, unit) values ('2', '2020-02-11', '80')", + "insert into Orders (product_id, order_date, unit) values ('3', '2020-02-17', '2')", + "insert into Orders (product_id, order_date, unit) values ('3', '2020-02-24', '3')", + "insert into Orders (product_id, order_date, unit) values ('4', '2020-03-01', '20')", + "insert into Orders (product_id, order_date, unit) values ('4', '2020-03-04', '30')", + "insert into Orders (product_id, order_date, unit) values ('4', '2020-03-04', '60')", + "insert into Orders (product_id, order_date, unit) values ('5', '2020-02-25', '50')", + "insert into Orders (product_id, order_date, unit) values ('5', '2020-02-27', '50')", + "insert into Orders (product_id, order_date, unit) values ('5', '2020-03-01', '50')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\": {\"Products\": [\"product_id\", \"product_name\", \"product_category\"], \"Orders\": [\"product_id\", \"order_date\", \"unit\"]}, \"rows\": {\"Products\": [[1, \"Leetcode Solutions\", \"Book\"], [2, \"Jewels of Stringology\", \"Book\"], [3, \"HP\", \"Laptop\"], [4, \"Lenovo\", \"Laptop\"], [5, \"Leetcode Kit\", \"T-shirt\"]], \"Orders\": [[1, \"2020-02-05\", 60], [1, \"2020-02-10\", 70], [2, \"2020-01-18\", 30], [2, \"2020-02-11\", 80], [3, \"2020-02-17\", 2], [3, \"2020-02-24\", 3], [4, \"2020-03-01\", 20], [4, \"2020-03-04\", 30], [4, \"2020-03-04\", 60], [5, \"2020-02-25\", 50], [5, \"2020-02-27\", 50], [5, \"2020-03-01\", 50]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/managers-with-at-least-5-direct-reports.json b/leetcode-cn/originData/managers-with-at-least-5-direct-reports.json new file mode 100644 index 00000000..7faf2c95 --- /dev/null +++ b/leetcode-cn/originData/managers-with-at-least-5-direct-reports.json @@ -0,0 +1,98 @@ +{ + "data": { + "question": { + "questionId": "570", + "questionFrontendId": "570", + "categoryTitle": "Database", + "boundTopicId": 2652, + "title": "Managers with at Least 5 Direct Reports", + "titleSlug": "managers-with-at-least-5-direct-reports", + "content": "

Table: Employee

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| id          | int     |\n| name        | varchar |\n| department  | varchar |\n| managerId   | int     |\n+-------------+---------+\nid is the primary key (column with unique values) for this table.\nEach row of this table indicates the name of an employee, their department, and the id of their manager.\nIf managerId is null, then the employee does not have a manager.\nNo employee will be the manager of themself.\n
\n\n

 

\n\n

Write a solution to find managers with at least five direct reports.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nEmployee table:\n+-----+-------+------------+-----------+\n| id  | name  | department | managerId |\n+-----+-------+------------+-----------+\n| 101 | John  | A          | null      |\n| 102 | Dan   | A          | 101       |\n| 103 | James | A          | 101       |\n| 104 | Amy   | A          | 101       |\n| 105 | Anne  | A          | 101       |\n| 106 | Ron   | B          | 101       |\n+-----+-------+------------+-----------+\nOutput: \n+------+\n| name |\n+------+\n| John |\n+------+\n
\n", + "translatedTitle": "至少有5名直接下属的经理", + "translatedContent": "

表: Employee

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| id          | int     |\n| name        | varchar |\n| department  | varchar |\n| managerId   | int     |\n+-------------+---------+\nid 是此表的主键(具有唯一值的列)。\n该表的每一行表示雇员的名字、他们的部门和他们的经理的id。\n如果managerId为空,则该员工没有经理。\n没有员工会成为自己的管理者。\n
\n\n

 

\n\n

编写一个解决方案,找出至少有五个直接下属的经理。

\n\n

任意顺序 返回结果表。

\n\n

查询结果格式如下所示。

\n\n

 

\n\n

示例 1:

\n\n
\n输入: \nEmployee 表:\n+-----+-------+------------+-----------+\n| id  | name  | department | managerId |\n+-----+-------+------------+-----------+\n| 101 | John  | A          | Null      |\n| 102 | Dan   | A          | 101       |\n| 103 | James | A          | 101       |\n| 104 | Amy   | A          | 101       |\n| 105 | Anne  | A          | 101       |\n| 106 | Ron   | B          | 101       |\n+-----+-------+------------+-----------+\n输出: \n+------+\n| name |\n+------+\n| John |\n+------+
\n", + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 100, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef find_managers(employee: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"58.2K\", \"totalSubmission\": \"97.9K\", \"totalAcceptedRaw\": 58187, \"totalSubmissionRaw\": 97929, \"acRate\": \"59.4%\"}", + "hints": [ + "Try to get all the mangerIDs that have count bigger than 5", + "Use the last hint's result as a table and do join with origin table at id equals to managerId", + "This is a very good example to show the performance of SQL code. Try to work out other solutions and you may be surprised by running time difference.", + "If your solution uses 'IN' function and runs more than 5 seconds, try to optimize it by using 'JOIN' instead." + ], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\": {\"Employee\": [\"id\", \"name\", \"department\", \"managerId\"]}, \"rows\": {\"Employee\": [[101, \"John\", \"A\", null],[102, \"Dan\", \"A\", 101], [103, \"James\", \"A\", 101], [104, \"Amy\", \"A\", 101], [105, \"Anne\", \"A\", 101], [106, \"Ron\", \"B\", 101]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Employee (id int, name varchar(255), department varchar(255), managerId int)\"],\"mssql\":[\"Create table Employee (id int, name varchar(255), department varchar(255), managerId int)\"],\"oraclesql\":[\"Create table Employee (id int, name varchar(255), department varchar(255), managerId int)\"],\"database\":true,\"name\":\"find_managers\",\"pythondata\":[\"Employee = pd.DataFrame([], columns=['id', 'name', 'department', 'managerId']).astype({'id':'Int64', 'name':'object', 'department':'object', 'managerId':'Int64'})\"],\"manual\":false,\"postgresql\":[\"\\nCreate table If Not Exists Employee (id int, name varchar(255), department varchar(255), managerId int)\"],\"database_schema\":{\"Employee\":{\"id\":\"INT\",\"name\":\"VARCHAR(255)\",\"department\":\"VARCHAR(255)\",\"managerId\":\"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Employee (id int, name varchar(255), department varchar(255), managerId int)", + "Truncate table Employee", + "insert into Employee (id, name, department, managerId) values ('101', 'John', 'A', 'None')", + "insert into Employee (id, name, department, managerId) values ('102', 'Dan', 'A', '101')", + "insert into Employee (id, name, department, managerId) values ('103', 'James', 'A', '101')", + "insert into Employee (id, name, department, managerId) values ('104', 'Amy', 'A', '101')", + "insert into Employee (id, name, department, managerId) values ('105', 'Anne', 'A', '101')", + "insert into Employee (id, name, department, managerId) values ('106', 'Ron', 'B', '101')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\": {\"Employee\": [\"id\", \"name\", \"department\", \"managerId\"]}, \"rows\": {\"Employee\": [[101, \"John\", \"A\", null],[102, \"Dan\", \"A\", 101], [103, \"James\", \"A\", 101], [104, \"Amy\", \"A\", 101], [105, \"Anne\", \"A\", 101], [106, \"Ron\", \"B\", 101]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/monthly-transactions-i.json b/leetcode-cn/originData/monthly-transactions-i.json new file mode 100644 index 00000000..f411f4ec --- /dev/null +++ b/leetcode-cn/originData/monthly-transactions-i.json @@ -0,0 +1,91 @@ +{ + "data": { + "question": { + "questionId": "1317", + "questionFrontendId": "1193", + "categoryTitle": "Database", + "boundTopicId": 27992, + "title": "Monthly Transactions I", + "titleSlug": "monthly-transactions-i", + "content": "

Table: Transactions

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| country       | varchar |\n| state         | enum    |\n| amount        | int     |\n| trans_date    | date    |\n+---------------+---------+\nid is the primary key of this table.\nThe table has information about incoming transactions.\nThe state column is an enum of type ["approved", "declined"].\n
\n\n

 

\n\n

Write an SQL query to find for each month and country, the number of transactions and their total amount, the number of approved transactions and their total amount.

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nTransactions table:\n+------+---------+----------+--------+------------+\n| id   | country | state    | amount | trans_date |\n+------+---------+----------+--------+------------+\n| 121  | US      | approved | 1000   | 2018-12-18 |\n| 122  | US      | declined | 2000   | 2018-12-19 |\n| 123  | US      | approved | 2000   | 2019-01-01 |\n| 124  | DE      | approved | 2000   | 2019-01-07 |\n+------+---------+----------+--------+------------+\nOutput: \n+----------+---------+-------------+----------------+--------------------+-----------------------+\n| month    | country | trans_count | approved_count | trans_total_amount | approved_total_amount |\n+----------+---------+-------------+----------------+--------------------+-----------------------+\n| 2018-12  | US      | 2           | 1              | 3000               | 1000                  |\n| 2019-01  | US      | 1           | 1              | 2000               | 2000                  |\n| 2019-01  | DE      | 1           | 1              | 2000               | 2000                  |\n+----------+---------+-------------+----------------+--------------------+-----------------------+\n
\n", + "translatedTitle": "每月交易 I", + "translatedContent": "

表:Transactions

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| country       | varchar |\n| state         | enum    |\n| amount        | int     |\n| trans_date    | date    |\n+---------------+---------+\nid 是这个表的主键。\n该表包含有关传入事务的信息。\nstate 列类型为 [\"approved\", \"declined\"] 之一。\n
\n\n

 

\n\n

编写一个 sql 查询来查找每个月和每个国家/地区的事务数及其总金额、已批准的事务数及其总金额。

\n\n

任意顺序 返回结果表。

\n\n

查询结果格式如下所示。

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nTransactions table:\n+------+---------+----------+--------+------------+\n| id   | country | state    | amount | trans_date |\n+------+---------+----------+--------+------------+\n| 121  | US      | approved | 1000   | 2018-12-18 |\n| 122  | US      | declined | 2000   | 2018-12-19 |\n| 123  | US      | approved | 2000   | 2019-01-01 |\n| 124  | DE      | approved | 2000   | 2019-01-07 |\n+------+---------+----------+--------+------------+\n输出:\n+----------+---------+-------------+----------------+--------------------+-----------------------+\n| month    | country | trans_count | approved_count | trans_total_amount | approved_total_amount |\n+----------+---------+-------------+----------------+--------------------+-----------------------+\n| 2018-12  | US      | 2           | 1              | 3000               | 1000                  |\n| 2019-01  | US      | 1           | 1              | 2000               | 2000                  |\n| 2019-01  | DE      | 1           | 1              | 2000               | 2000                  |\n+----------+---------+-------------+----------------+--------------------+-----------------------+
\n", + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 93, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef monthly_transactions(transactions: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"29K\", \"totalSubmission\": \"47.5K\", \"totalAcceptedRaw\": 28963, \"totalSubmissionRaw\": 47510, \"acRate\": \"61.0%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Transactions\":[\"id\",\"country\",\"state\",\"amount\",\"trans_date\"]},\"rows\":{\"Transactions\":[[121,\"US\",\"approved\",1000,\"2018-12-18\"],[122,\"US\",\"declined\",2000,\"2018-12-19\"],[123,\"US\",\"approved\",2000,\"2019-01-01\"],[124,\"DE\",\"approved\",2000,\"2019-01-07\"]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Transactions (id int, country varchar(4), state enum('approved', 'declined'), amount int, trans_date date)\"],\"mssql\":[\"Create table Transactions (id int, country varchar(4), state varchar(10) check(state in ('approved', 'declined')), amount int, trans_date date)\"],\"oraclesql\":[\"Create table Transactions (id int, country varchar(4), state varchar(10) check(state in ('approved', 'declined')), amount int, trans_date date)\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"],\"database\":true,\"name\":\"monthly_transactions\",\"pythondata\":[\"Transactions = pd.DataFrame([], columns=['id', 'country', 'state', 'amount', 'trans_date']).astype({'id':'Int64', 'country':'object', 'state':'object', 'amount':'Int64', 'trans_date':'datetime64[ns]'})\"],\"postgresql\":[\"Create table If Not Exists Transactions (id int, country varchar(4), state VARCHAR(30) CHECK (state IN ('approved', 'declined')), amount int, trans_date date)\\n\\n\"],\"database_schema\":{\"Transactions\":{\"id\":\"INT\",\"country\":\"VARCHAR(4)\",\"state\":\"ENUM('approved', 'declined')\",\"amount\":\"INT\",\"trans_date\":\"DATE\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Transactions (id int, country varchar(4), state enum('approved', 'declined'), amount int, trans_date date)", + "Truncate table Transactions", + "insert into Transactions (id, country, state, amount, trans_date) values ('121', 'US', 'approved', '1000', '2018-12-18')", + "insert into Transactions (id, country, state, amount, trans_date) values ('122', 'US', 'declined', '2000', '2018-12-19')", + "insert into Transactions (id, country, state, amount, trans_date) values ('123', 'US', 'approved', '2000', '2019-01-01')", + "insert into Transactions (id, country, state, amount, trans_date) values ('124', 'DE', 'approved', '2000', '2019-01-07')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Transactions\":[\"id\",\"country\",\"state\",\"amount\",\"trans_date\"]},\"rows\":{\"Transactions\":[[121,\"US\",\"approved\",1000,\"2018-12-18\"],[122,\"US\",\"declined\",2000,\"2018-12-19\"],[123,\"US\",\"approved\",2000,\"2019-01-01\"],[124,\"DE\",\"approved\",2000,\"2019-01-07\"]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/movie-rating.json b/leetcode-cn/originData/movie-rating.json new file mode 100644 index 00000000..f5e8b02e --- /dev/null +++ b/leetcode-cn/originData/movie-rating.json @@ -0,0 +1,107 @@ +{ + "data": { + "question": { + "questionId": "1480", + "questionFrontendId": "1341", + "categoryTitle": "Database", + "boundTopicId": 90536, + "title": "Movie Rating", + "titleSlug": "movie-rating", + "content": "

Table: Movies

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| movie_id      | int     |\n| title         | varchar |\n+---------------+---------+\nmovie_id is the primary key (column with unique values) for this table.\ntitle is the name of the movie.\n
\n\n

 

\n\n

Table: Users

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| name          | varchar |\n+---------------+---------+\nuser_id is the primary key (column with unique values) for this table.\n
\n\n

 

\n\n

Table: MovieRating

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| movie_id      | int     |\n| user_id       | int     |\n| rating        | int     |\n| created_at    | date    |\n+---------------+---------+\n(movie_id, user_id) is the primary key (column with unique values) for this table.\nThis table contains the rating of a movie by a user in their review.\ncreated_at is the user's review date. \n
\n\n

 

\n\n

Write a solution to:

\n\n
    \n\t
  • Find the name of the user who has rated the greatest number of movies. In case of a tie, return the lexicographically smaller user name.
  • \n\t
  • Find the movie name with the highest average rating in February 2020. In case of a tie, return the lexicographically smaller movie name.
  • \n
\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nMovies table:\n+-------------+--------------+\n| movie_id    |  title       |\n+-------------+--------------+\n| 1           | Avengers     |\n| 2           | Frozen 2     |\n| 3           | Joker        |\n+-------------+--------------+\nUsers table:\n+-------------+--------------+\n| user_id     |  name        |\n+-------------+--------------+\n| 1           | Daniel       |\n| 2           | Monica       |\n| 3           | Maria        |\n| 4           | James        |\n+-------------+--------------+\nMovieRating table:\n+-------------+--------------+--------------+-------------+\n| movie_id    | user_id      | rating       | created_at  |\n+-------------+--------------+--------------+-------------+\n| 1           | 1            | 3            | 2020-01-12  |\n| 1           | 2            | 4            | 2020-02-11  |\n| 1           | 3            | 2            | 2020-02-12  |\n| 1           | 4            | 1            | 2020-01-01  |\n| 2           | 1            | 5            | 2020-02-17  | \n| 2           | 2            | 2            | 2020-02-01  | \n| 2           | 3            | 2            | 2020-03-01  |\n| 3           | 1            | 3            | 2020-02-22  | \n| 3           | 2            | 4            | 2020-02-25  | \n+-------------+--------------+--------------+-------------+\nOutput: \n+--------------+\n| results      |\n+--------------+\n| Daniel       |\n| Frozen 2     |\n+--------------+\nExplanation: \nDaniel and Monica have rated 3 movies ("Avengers", "Frozen 2" and "Joker") but Daniel is smaller lexicographically.\nFrozen 2 and Joker have a rating average of 3.5 in February but Frozen 2 is smaller lexicographically.\n
\n", + "translatedTitle": "电影评分", + "translatedContent": "

表:Movies

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| movie_id      | int     |\n| title         | varchar |\n+---------------+---------+\nmovie_id 是这个表的主键(具有唯一值的列)。\ntitle 是电影的名字。\n
\n\n

表:Users

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| name          | varchar |\n+---------------+---------+\nuser_id 是表的主键(具有唯一值的列)。\n
\n\n

表:MovieRating

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| movie_id      | int     |\n| user_id       | int     |\n| rating        | int     |\n| created_at    | date    |\n+---------------+---------+\n(movie_id, user_id) 是这个表的主键(具有唯一值的列的组合)。\n这个表包含用户在其评论中对电影的评分 rating 。\ncreated_at 是用户的点评日期。 \n
\n\n

 

\n\n

请你编写一个解决方案:

\n\n
    \n\t
  • 查找评论电影数量最多的用户名。如果出现平局,返回字典序较小的用户名。
  • \n\t
  • 查找在 February 2020 平均评分最高 的电影名称。如果出现平局,返回字典序较小的电影名称。
  • \n
\n\n

字典序 ,即按字母在字典中出现顺序对字符串排序,字典序较小则意味着排序靠前。

\n\n

返回结果格式如下例所示。

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nMovies 表:\n+-------------+--------------+\n| movie_id    |  title       |\n+-------------+--------------+\n| 1           | Avengers     |\n| 2           | Frozen 2     |\n| 3           | Joker        |\n+-------------+--------------+\nUsers 表:\n+-------------+--------------+\n| user_id     |  name        |\n+-------------+--------------+\n| 1           | Daniel       |\n| 2           | Monica       |\n| 3           | Maria        |\n| 4           | James        |\n+-------------+--------------+\nMovieRating 表:\n+-------------+--------------+--------------+-------------+\n| movie_id    | user_id      | rating       | created_at  |\n+-------------+--------------+--------------+-------------+\n| 1           | 1            | 3            | 2020-01-12  |\n| 1           | 2            | 4            | 2020-02-11  |\n| 1           | 3            | 2            | 2020-02-12  |\n| 1           | 4            | 1            | 2020-01-01  |\n| 2           | 1            | 5            | 2020-02-17  | \n| 2           | 2            | 2            | 2020-02-01  | \n| 2           | 3            | 2            | 2020-03-01  |\n| 3           | 1            | 3            | 2020-02-22  | \n| 3           | 2            | 4            | 2020-02-25  | \n+-------------+--------------+--------------+-------------+\n输出:\nResult 表:\n+--------------+\n| results      |\n+--------------+\n| Daniel       |\n| Frozen 2     |\n+--------------+\n解释:\nDaniel 和 Monica 都点评了 3 部电影(\"Avengers\", \"Frozen 2\" 和 \"Joker\") 但是 Daniel 字典序比较小。\nFrozen 2 和 Joker 在 2 月的评分都是 3.5,但是 Frozen 2 的字典序比较小。\n
\n", + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 55, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef movie_rating(movies: pd.DataFrame, users: pd.DataFrame, movie_rating: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"16.7K\", \"totalSubmission\": \"45.8K\", \"totalAcceptedRaw\": 16688, \"totalSubmissionRaw\": 45846, \"acRate\": \"36.4%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\": {\"Movies\": [\"movie_id\", \"title\"], \"Users\": [\"user_id\", \"name\"], \"MovieRating\": [\"movie_id\", \"user_id\", \"rating\", \"created_at\"]}, \"rows\": {\"Movies\": [[1, \"Avengers\"], [2, \"Frozen 2\"], [3, \"Joker\"]], \"Users\": [[1, \"Daniel\"], [2, \"Monica\"], [3, \"Maria\"], [4, \"James\"]], \"MovieRating\": [[1, 1, 3, \"2020-01-12\"], [1, 2, 4, \"2020-02-11\"], [1, 3, 2, \"2020-02-12\"], [1, 4, 1, \"2020-01-01\"], [2, 1, 5, \"2020-02-17\"], [2, 2, 2, \"2020-02-01\"], [2, 3, 2, \"2020-03-01\"], [3, 1, 3, \"2020-02-22\"], [3, 2, 4, \"2020-02-25\"]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Movies (movie_id int, title varchar(30))\",\"Create table If Not Exists Users (user_id int, name varchar(30))\",\"Create table If Not Exists MovieRating (movie_id int, user_id int, rating int, created_at date)\"],\"mssql\":[\"Create table Movies (movie_id int, title varchar(30))\",\"Create table Users (user_id int, name varchar(30))\",\"Create table MovieRating (movie_id int, user_id int, rating int, created_at date)\"],\"oraclesql\":[\"Create table Movies (movie_id int, title varchar(30))\",\"Create table Users (user_id int, name varchar(30))\",\"Create table MovieRating (movie_id int, user_id int, rating int, created_at date)\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"],\"database\":true,\"name\":\"movie_rating\",\"pythondata\":[\"Movies = pd.DataFrame([], columns=['movie_id', 'title']).astype({'movie_id':'Int64', 'title':'object'})\",\"Users = pd.DataFrame([], columns=['user_id', 'name']).astype({'user_id':'Int64', 'name':'object'})\",\"MovieRating = pd.DataFrame([], columns=['movie_id', 'user_id', 'rating', 'created_at']).astype({'movie_id':'Int64', 'user_id':'Int64', 'rating':'Int64', 'created_at':'datetime64[ns]'})\"],\"postgresql\":[\"\\nCreate table If Not Exists Movies (movie_id int, title varchar(30))\",\"Create table If Not Exists Users (user_id int, name varchar(30))\",\"Create table If Not Exists MovieRating (movie_id int, user_id int, rating int, created_at date)\"],\"database_schema\":{\"Movies\":{\"movie_id\":\"INT\",\"title\":\"VARCHAR(30)\"},\"Users\":{\"user_id\":\"INT\",\"name\":\"VARCHAR(30)\"},\"MovieRating\":{\"movie_id\":\"INT\",\"user_id\":\"INT\",\"rating\":\"INT\",\"created_at\":\"DATE\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Movies (movie_id int, title varchar(30))", + "Create table If Not Exists Users (user_id int, name varchar(30))", + "Create table If Not Exists MovieRating (movie_id int, user_id int, rating int, created_at date)", + "Truncate table Movies", + "insert into Movies (movie_id, title) values ('1', 'Avengers')", + "insert into Movies (movie_id, title) values ('2', 'Frozen 2')", + "insert into Movies (movie_id, title) values ('3', 'Joker')", + "Truncate table Users", + "insert into Users (user_id, name) values ('1', 'Daniel')", + "insert into Users (user_id, name) values ('2', 'Monica')", + "insert into Users (user_id, name) values ('3', 'Maria')", + "insert into Users (user_id, name) values ('4', 'James')", + "Truncate table MovieRating", + "insert into MovieRating (movie_id, user_id, rating, created_at) values ('1', '1', '3', '2020-01-12')", + "insert into MovieRating (movie_id, user_id, rating, created_at) values ('1', '2', '4', '2020-02-11')", + "insert into MovieRating (movie_id, user_id, rating, created_at) values ('1', '3', '2', '2020-02-12')", + "insert into MovieRating (movie_id, user_id, rating, created_at) values ('1', '4', '1', '2020-01-01')", + "insert into MovieRating (movie_id, user_id, rating, created_at) values ('2', '1', '5', '2020-02-17')", + "insert into MovieRating (movie_id, user_id, rating, created_at) values ('2', '2', '2', '2020-02-01')", + "insert into MovieRating (movie_id, user_id, rating, created_at) values ('2', '3', '2', '2020-03-01')", + "insert into MovieRating (movie_id, user_id, rating, created_at) values ('3', '1', '3', '2020-02-22')", + "insert into MovieRating (movie_id, user_id, rating, created_at) values ('3', '2', '4', '2020-02-25')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\": {\"Movies\": [\"movie_id\", \"title\"], \"Users\": [\"user_id\", \"name\"], \"MovieRating\": [\"movie_id\", \"user_id\", \"rating\", \"created_at\"]}, \"rows\": {\"Movies\": [[1, \"Avengers\"], [2, \"Frozen 2\"], [3, \"Joker\"]], \"Users\": [[1, \"Daniel\"], [2, \"Monica\"], [3, \"Maria\"], [4, \"James\"]], \"MovieRating\": [[1, 1, 3, \"2020-01-12\"], [1, 2, 4, \"2020-02-11\"], [1, 3, 2, \"2020-02-12\"], [1, 4, 1, \"2020-01-01\"], [2, 1, 5, \"2020-02-17\"], [2, 2, 2, \"2020-02-01\"], [2, 3, 2, \"2020-03-01\"], [3, 1, 3, \"2020-02-22\"], [3, 2, 4, \"2020-02-25\"]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/number-of-unique-subjects-taught-by-each-teacher.json b/leetcode-cn/originData/number-of-unique-subjects-taught-by-each-teacher.json new file mode 100644 index 00000000..5c92bbbe --- /dev/null +++ b/leetcode-cn/originData/number-of-unique-subjects-taught-by-each-teacher.json @@ -0,0 +1,94 @@ +{ + "data": { + "question": { + "questionId": "2495", + "questionFrontendId": "2356", + "categoryTitle": "Database", + "boundTopicId": 1706030, + "title": "Number of Unique Subjects Taught by Each Teacher", + "titleSlug": "number-of-unique-subjects-taught-by-each-teacher", + "content": "

Table: Teacher

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| teacher_id  | int  |\n| subject_id  | int  |\n| dept_id     | int  |\n+-------------+------+\n(subject_id, dept_id) is the primary key (combinations of columns with unique values) of this table.\nEach row in this table indicates that the teacher with teacher_id teaches the subject subject_id in the department dept_id.\n
\n\n

 

\n\n

Write a solution to calculate the number of unique subjects each teacher teaches in the university.

\n\n

Return the result table in any order.

\n\n

The result format is shown in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nTeacher table:\n+------------+------------+---------+\n| teacher_id | subject_id | dept_id |\n+------------+------------+---------+\n| 1          | 2          | 3       |\n| 1          | 2          | 4       |\n| 1          | 3          | 3       |\n| 2          | 1          | 1       |\n| 2          | 2          | 1       |\n| 2          | 3          | 1       |\n| 2          | 4          | 1       |\n+------------+------------+---------+\nOutput:  \n+------------+-----+\n| teacher_id | cnt |\n+------------+-----+\n| 1          | 2   |\n| 2          | 4   |\n+------------+-----+\nExplanation: \nTeacher 1:\n  - They teach subject 2 in departments 3 and 4.\n  - They teach subject 3 in department 3.\nTeacher 2:\n  - They teach subject 1 in department 1.\n  - They teach subject 2 in department 1.\n  - They teach subject 3 in department 1.\n  - They teach subject 4 in department 1.\n
\n", + "translatedTitle": "每位教师所教授的科目种类的数量", + "translatedContent": "

表: Teacher

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| teacher_id  | int  |\n| subject_id  | int  |\n| dept_id     | int  |\n+-------------+------+\n在 SQL 中,(subject_id, dept_id) 是该表的主键。\n该表中的每一行都表示带有 teacher_id 的教师在系 dept_id 中教授科目 subject_id。\n
\n\n

 

\n\n

查询每位老师在大学里教授的科目种类的数量。

\n\n

任意顺序 返回结果表。

\n\n

查询结果格式示例如下。

\n\n

 

\n\n

示例 1:

\n\n
\n输入: \nTeacher 表:\n+------------+------------+---------+\n| teacher_id | subject_id | dept_id |\n+------------+------------+---------+\n| 1          | 2          | 3       |\n| 1          | 2          | 4       |\n| 1          | 3          | 3       |\n| 2          | 1          | 1       |\n| 2          | 2          | 1       |\n| 2          | 3          | 1       |\n| 2          | 4          | 1       |\n+------------+------------+---------+\n输出:  \n+------------+-----+\n| teacher_id | cnt |\n+------------+-----+\n| 1          | 2   |\n| 2          | 4   |\n+------------+-----+\n解释: \n教师 1:\n  - 他在 3、4 系教科目 2。\n  - 他在 3 系教科目 3。\n教师 2:\n  - 他在 1 系教科目 1。\n  - 他在 1 系教科目 2。\n  - 他在 1 系教科目 3。\n  - 他在 1 系教科目 4。
\n", + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 19, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef count_unique_subjects(teacher: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"16.4K\", \"totalSubmission\": \"19.7K\", \"totalAcceptedRaw\": 16351, \"totalSubmissionRaw\": 19700, \"acRate\": \"83.0%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Teacher\":[\"teacher_id\",\"subject_id\",\"dept_id\"]},\"rows\":{\"Teacher\":[[1,2,3],[1,2,4],[1,3,3],[2,1,1],[2,2,1],[2,3,1],[2,4,1]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Teacher (teacher_id int, subject_id int, dept_id int)\"],\"mssql\":[\"Create table Teacher (teacher_id int, subject_id int, dept_id int)\"],\"oraclesql\":[\"Create table Teacher (teacher_id int, subject_id int, dept_id int)\"],\"database\":true,\"name\":\"count_unique_subjects\",\"pythondata\":[\"Teacher = pd.DataFrame([], columns=['teacher_id', 'subject_id', 'dept_id']).astype({'teacher_id':'Int64', 'subject_id':'Int64', 'dept_id':'Int64'})\"],\"postgresql\":[\"Create table If Not Exists Teacher (teacher_id int, subject_id int, dept_id int)\"],\"database_schema\":{\"Teacher\":{\"teacher_id\":\"INT\",\"subject_id\":\"INT\",\"dept_id\":\"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Teacher (teacher_id int, subject_id int, dept_id int)", + "Truncate table Teacher", + "insert into Teacher (teacher_id, subject_id, dept_id) values ('1', '2', '3')", + "insert into Teacher (teacher_id, subject_id, dept_id) values ('1', '2', '4')", + "insert into Teacher (teacher_id, subject_id, dept_id) values ('1', '3', '3')", + "insert into Teacher (teacher_id, subject_id, dept_id) values ('2', '1', '1')", + "insert into Teacher (teacher_id, subject_id, dept_id) values ('2', '2', '1')", + "insert into Teacher (teacher_id, subject_id, dept_id) values ('2', '3', '1')", + "insert into Teacher (teacher_id, subject_id, dept_id) values ('2', '4', '1')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Teacher\":[\"teacher_id\",\"subject_id\",\"dept_id\"]},\"rows\":{\"Teacher\":[[1,2,3],[1,2,4],[1,3,3],[2,1,1],[2,2,1],[2,3,1],[2,4,1]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/percentage-of-users-attended-a-contest.json b/leetcode-cn/originData/percentage-of-users-attended-a-contest.json new file mode 100644 index 00000000..011edb4d --- /dev/null +++ b/leetcode-cn/originData/percentage-of-users-attended-a-contest.json @@ -0,0 +1,104 @@ +{ + "data": { + "question": { + "questionId": "1773", + "questionFrontendId": "1633", + "categoryTitle": "Database", + "boundTopicId": 460450, + "title": "Percentage of Users Attended a Contest", + "titleSlug": "percentage-of-users-attended-a-contest", + "content": "

Table: Users

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| user_id     | int     |\n| user_name   | varchar |\n+-------------+---------+\nuser_id is the primary key (column with unique values) for this table.\nEach row of this table contains the name and the id of a user.\n
\n\n

 

\n\n

Table: Register

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| contest_id  | int     |\n| user_id     | int     |\n+-------------+---------+\n(contest_id, user_id) is the primary key (combination of columns with unique values) for this table.\nEach row of this table contains the id of a user and the contest they registered into.\n
\n\n

 

\n\n

Write a solution to find the percentage of the users registered in each contest rounded to two decimals.

\n\n

Return the result table ordered by percentage in descending order. In case of a tie, order it by contest_id in ascending order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nUsers table:\n+---------+-----------+\n| user_id | user_name |\n+---------+-----------+\n| 6       | Alice     |\n| 2       | Bob       |\n| 7       | Alex      |\n+---------+-----------+\nRegister table:\n+------------+---------+\n| contest_id | user_id |\n+------------+---------+\n| 215        | 6       |\n| 209        | 2       |\n| 208        | 2       |\n| 210        | 6       |\n| 208        | 6       |\n| 209        | 7       |\n| 209        | 6       |\n| 215        | 7       |\n| 208        | 7       |\n| 210        | 2       |\n| 207        | 2       |\n| 210        | 7       |\n+------------+---------+\nOutput: \n+------------+------------+\n| contest_id | percentage |\n+------------+------------+\n| 208        | 100.0      |\n| 209        | 100.0      |\n| 210        | 100.0      |\n| 215        | 66.67      |\n| 207        | 33.33      |\n+------------+------------+\nExplanation: \nAll the users registered in contests 208, 209, and 210. The percentage is 100% and we sort them in the answer table by contest_id in ascending order.\nAlice and Alex registered in contest 215 and the percentage is ((2/3) * 100) = 66.67%\nBob registered in contest 207 and the percentage is ((1/3) * 100) = 33.33%\n
\n", + "translatedTitle": "各赛事的用户注册率", + "translatedContent": "

用户表: Users

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| user_id     | int     |\n| user_name   | varchar |\n+-------------+---------+\nuser_id 是该表的主键(具有唯一值的列)。\n该表中的每行包括用户 ID 和用户名。
\n\n

 

\n\n

注册表: Register

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| contest_id  | int     |\n| user_id     | int     |\n+-------------+---------+\n(contest_id, user_id) 是该表的主键(具有唯一值的列的组合)。\n该表中的每行包含用户的 ID 和他们注册的赛事。
\n\n

 

\n\n

编写解决方案统计出各赛事的用户注册百分率,保留两位小数。

\n\n

返回的结果表按 percentage 的 降序 排序,若相同则按 contest_id 的 升序 排序。

\n\n

返回结果如下示例所示。

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nUsers 表:\n+---------+-----------+\n| user_id | user_name |\n+---------+-----------+\n| 6       | Alice     |\n| 2       | Bob       |\n| 7       | Alex      |\n+---------+-----------+\n\nRegister 表:\n+------------+---------+\n| contest_id | user_id |\n+------------+---------+\n| 215        | 6       |\n| 209        | 2       |\n| 208        | 2       |\n| 210        | 6       |\n| 208        | 6       |\n| 209        | 7       |\n| 209        | 6       |\n| 215        | 7       |\n| 208        | 7       |\n| 210        | 2       |\n| 207        | 2       |\n| 210        | 7       |\n+------------+---------+\n输出:\n+------------+------------+\n| contest_id | percentage |\n+------------+------------+\n| 208        | 100.0      |\n| 209        | 100.0      |\n| 210        | 100.0      |\n| 215        | 66.67      |\n| 207        | 33.33      |\n+------------+------------+\n解释:\n所有用户都注册了 208、209 和 210 赛事,因此这些赛事的注册率为 100% ,我们按 contest_id 的降序排序加入结果表中。\nAlice 和 Alex 注册了 215 赛事,注册率为 ((2/3) * 100) = 66.67%\nBob 注册了 207 赛事,注册率为 ((1/3) * 100) = 33.33%
\n", + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 55, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef users_percentage(users: pd.DataFrame, register: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"24.5K\", \"totalSubmission\": \"41K\", \"totalAcceptedRaw\": 24505, \"totalSubmissionRaw\": 40965, \"acRate\": \"59.8%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Users\":[\"user_id\",\"user_name\"],\"Register\":[\"contest_id\",\"user_id\"]},\"rows\":{\"Users\":[[6,\"Alice\"],[2,\"Bob\"],[7,\"Alex\"]],\"Register\":[[215,6],[209,2],[208,2],[210,6],[208,6],[209,7],[209,6],[215,7],[208,7],[210,2],[207,2],[210,7]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Users (user_id int, user_name varchar(20))\",\"Create table If Not Exists Register (contest_id int, user_id int)\"],\"mssql\":[\"Create table Users (user_id int, user_name varchar(20))\",\"Create table Register (contest_id int, user_id int)\"],\"oraclesql\":[\"Create table Users (user_id int, user_name varchar(20))\",\"Create table Register (contest_id int, user_id int)\"],\"database\":true,\"name\":\"users_percentage\",\"pythondata\":[\"Users = pd.DataFrame([], columns=['user_id', 'user_name']).astype({'user_id':'Int64', 'user_name':'object'})\",\"Register = pd.DataFrame([], columns=['contest_id', 'user_id']).astype({'contest_id':'Int64', 'user_id':'Int64'})\"],\"postgresql\":[\"\\nCreate table If Not Exists Users (user_id int, user_name varchar(20))\\n\",\"Create table If Not Exists Register (contest_id int, user_id int)\"],\"database_schema\":{\"Users\":{\"user_id\":\"INT\",\"user_name\":\"VARCHAR(20)\"},\"Register\":{\"contest_id\":\"INT\",\"user_id\":\"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Users (user_id int, user_name varchar(20))", + "Create table If Not Exists Register (contest_id int, user_id int)", + "Truncate table Users", + "insert into Users (user_id, user_name) values ('6', 'Alice')", + "insert into Users (user_id, user_name) values ('2', 'Bob')", + "insert into Users (user_id, user_name) values ('7', 'Alex')", + "Truncate table Register", + "insert into Register (contest_id, user_id) values ('215', '6')", + "insert into Register (contest_id, user_id) values ('209', '2')", + "insert into Register (contest_id, user_id) values ('208', '2')", + "insert into Register (contest_id, user_id) values ('210', '6')", + "insert into Register (contest_id, user_id) values ('208', '6')", + "insert into Register (contest_id, user_id) values ('209', '7')", + "insert into Register (contest_id, user_id) values ('209', '6')", + "insert into Register (contest_id, user_id) values ('215', '7')", + "insert into Register (contest_id, user_id) values ('208', '7')", + "insert into Register (contest_id, user_id) values ('210', '2')", + "insert into Register (contest_id, user_id) values ('207', '2')", + "insert into Register (contest_id, user_id) values ('210', '7')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Users\":[\"user_id\",\"user_name\"],\"Register\":[\"contest_id\",\"user_id\"]},\"rows\":{\"Users\":[[6,\"Alice\"],[2,\"Bob\"],[7,\"Alex\"]],\"Register\":[[215,6],[209,2],[208,2],[210,6],[208,6],[209,7],[209,6],[215,7],[208,7],[210,2],[207,2],[210,7]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/primary-department-for-each-employee.json b/leetcode-cn/originData/primary-department-for-each-employee.json new file mode 100644 index 00000000..75c7eb37 --- /dev/null +++ b/leetcode-cn/originData/primary-department-for-each-employee.json @@ -0,0 +1,94 @@ +{ + "data": { + "question": { + "questionId": "1942", + "questionFrontendId": "1789", + "categoryTitle": "Database", + "boundTopicId": 654757, + "title": "Primary Department for Each Employee", + "titleSlug": "primary-department-for-each-employee", + "content": "

Table: Employee

\n\n
\n+---------------+---------+\n| Column Name   |  Type   |\n+---------------+---------+\n| employee_id   | int     |\n| department_id | int     |\n| primary_flag  | varchar |\n+---------------+---------+\n(employee_id, department_id) is the primary key (combination of columns with unique values) for this table.\nemployee_id is the id of the employee.\ndepartment_id is the id of the department to which the employee belongs.\nprimary_flag is an ENUM (category) of type ('Y', 'N'). If the flag is 'Y', the department is the primary department for the employee. If the flag is 'N', the department is not the primary.\n
\n\n

 

\n\n

Employees can belong to multiple departments. When the employee joins other departments, they need to decide which department is their primary department. Note that when an employee belongs to only one department, their primary column is 'N'.

\n\n

Write a solution to report all the employees with their primary department. For employees who belong to one department, report their only department.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nEmployee table:\n+-------------+---------------+--------------+\n| employee_id | department_id | primary_flag |\n+-------------+---------------+--------------+\n| 1           | 1             | N            |\n| 2           | 1             | Y            |\n| 2           | 2             | N            |\n| 3           | 3             | N            |\n| 4           | 2             | N            |\n| 4           | 3             | Y            |\n| 4           | 4             | N            |\n+-------------+---------------+--------------+\nOutput: \n+-------------+---------------+\n| employee_id | department_id |\n+-------------+---------------+\n| 1           | 1             |\n| 2           | 1             |\n| 3           | 3             |\n| 4           | 3             |\n+-------------+---------------+\nExplanation: \n- The Primary department for employee 1 is 1.\n- The Primary department for employee 2 is 1.\n- The Primary department for employee 3 is 3.\n- The Primary department for employee 4 is 3.\n
\n", + "translatedTitle": "员工的直属部门", + "translatedContent": "

表:Employee

\n\n
\n+---------------+---------+\n| Column Name   |  Type   |\n+---------------+---------+\n| employee_id   | int     |\n| department_id | int     |\n| primary_flag  | varchar |\n+---------------+---------+\n这张表的主键为 employee_id, department_id (具有唯一值的列的组合)\nemployee_id 是员工的ID\ndepartment_id 是部门的ID,表示员工与该部门有关系\nprimary_flag 是一个枚举类型,值分别为('Y', 'N'). 如果值为'Y',表示该部门是员工的直属部门。 如果值是'N',则否\n
\n\n

 

\n\n

一个员工可以属于多个部门。当一个员工加入超过一个部门的时候,他需要决定哪个部门是他的直属部门。请注意,当员工只加入一个部门的时候,那这个部门将默认为他的直属部门,虽然表记录的值为'N'.

\n\n

请编写解决方案,查出员工所属的直属部门。

\n\n

返回结果 没有顺序要求

\n\n

返回结果格式如下例子所示:

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nEmployee table:\n+-------------+---------------+--------------+\n| employee_id | department_id | primary_flag |\n+-------------+---------------+--------------+\n| 1           | 1             | N            |\n| 2           | 1             | Y            |\n| 2           | 2             | N            |\n| 3           | 3             | N            |\n| 4           | 2             | N            |\n| 4           | 3             | Y            |\n| 4           | 4             | N            |\n+-------------+---------------+--------------+\n输出:\n+-------------+---------------+\n| employee_id | department_id |\n+-------------+---------------+\n| 1           | 1             |\n| 2           | 1             |\n| 3           | 3             |\n| 4           | 3             |\n+-------------+---------------+\n解释:\n- 员工 1 的直属部门是 1\n- 员工 2 的直属部门是 1\n- 员工 3 的直属部门是 3\n- 员工 4 的直属部门是 3
\n\n

 

\n", + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 44, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef find_primary_department(employee: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"15.3K\", \"totalSubmission\": \"22.9K\", \"totalAcceptedRaw\": 15319, \"totalSubmissionRaw\": 22855, \"acRate\": \"67.0%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Employee\":[\"employee_id\",\"department_id\",\"primary_flag\"]},\"rows\":{\"Employee\":[[\"1\",\"1\",\"N\"],[\"2\",\"1\",\"Y\"],[\"2\",\"2\",\"N\"],[\"3\",\"3\",\"N\"],[\"4\",\"2\",\"N\"],[\"4\",\"3\",\"Y\"],[\"4\",\"4\",\"N\"]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Employee (employee_id int, department_id int, primary_flag ENUM('Y','N'))\"],\"mssql\":[\"Create table Employee (employee_id int, department_id int, primary_flag varchar(1) not null check(primary_flag in ('Y', 'N')))\"],\"oraclesql\":[\"Create table Employee (employee_id int, department_id int, primary_flag varchar(1) not null check(primary_flag in ('Y', 'N')))\"],\"database\":true,\"name\":\"find_primary_department\",\"pythondata\":[\"Employee = pd.DataFrame([], columns=['employee_id', 'department_id', 'primary_flag']).astype({'employee_id':'Int64', 'department_id':'Int64', 'primary_flag':'object'})\"],\"postgresql\":[\"Create table If Not Exists Employee (employee_id int, department_id int, primary_flag VARCHAR(30) CHECK (primary_flag IN ('Y','N')))\\n\"],\"database_schema\":{\"Employee\":{\"employee_id\":\"INT\",\"department_id\":\"INT\",\"primary_flag\":\"ENUM('Y', 'N')\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Employee (employee_id int, department_id int, primary_flag ENUM('Y','N'))", + "Truncate table Employee", + "insert into Employee (employee_id, department_id, primary_flag) values ('1', '1', 'N')", + "insert into Employee (employee_id, department_id, primary_flag) values ('2', '1', 'Y')", + "insert into Employee (employee_id, department_id, primary_flag) values ('2', '2', 'N')", + "insert into Employee (employee_id, department_id, primary_flag) values ('3', '3', 'N')", + "insert into Employee (employee_id, department_id, primary_flag) values ('4', '2', 'N')", + "insert into Employee (employee_id, department_id, primary_flag) values ('4', '3', 'Y')", + "insert into Employee (employee_id, department_id, primary_flag) values ('4', '4', 'N')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Employee\":[\"employee_id\",\"department_id\",\"primary_flag\"]},\"rows\":{\"Employee\":[[\"1\",\"1\",\"N\"],[\"2\",\"1\",\"Y\"],[\"2\",\"2\",\"N\"],[\"3\",\"3\",\"N\"],[\"4\",\"2\",\"N\"],[\"4\",\"3\",\"Y\"],[\"4\",\"4\",\"N\"]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/product-price-at-a-given-date.json b/leetcode-cn/originData/product-price-at-a-given-date.json new file mode 100644 index 00000000..1a4be927 --- /dev/null +++ b/leetcode-cn/originData/product-price-at-a-given-date.json @@ -0,0 +1,93 @@ +{ + "data": { + "question": { + "questionId": "1278", + "questionFrontendId": "1164", + "categoryTitle": "Database", + "boundTopicId": 33161, + "title": "Product Price at a Given Date", + "titleSlug": "product-price-at-a-given-date", + "content": "

Table: Products

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| new_price     | int     |\n| change_date   | date    |\n+---------------+---------+\n(product_id, change_date) is the primary key (combination of columns with unique values) of this table.\nEach row of this table indicates that the price of some product was changed to a new price at some date.
\n\n

 

\n\n

Write a solution to find the prices of all products on 2019-08-16. Assume the price of all products before any change is 10.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nProducts table:\n+------------+-----------+-------------+\n| product_id | new_price | change_date |\n+------------+-----------+-------------+\n| 1          | 20        | 2019-08-14  |\n| 2          | 50        | 2019-08-14  |\n| 1          | 30        | 2019-08-15  |\n| 1          | 35        | 2019-08-16  |\n| 2          | 65        | 2019-08-17  |\n| 3          | 20        | 2019-08-18  |\n+------------+-----------+-------------+\nOutput: \n+------------+-------+\n| product_id | price |\n+------------+-------+\n| 2          | 50    |\n| 1          | 35    |\n| 3          | 10    |\n+------------+-------+\n
\n", + "translatedTitle": "指定日期的产品价格", + "translatedContent": "

产品数据表: Products

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| new_price     | int     |\n| change_date   | date    |\n+---------------+---------+\n(product_id, change_date) 是此表的主键(具有唯一值的列组合)。\n这张表的每一行分别记录了 某产品 在某个日期 更改后 的新价格。
\n\n

 

\n\n

编写一个解决方案,找出在 2019-08-16 时全部产品的价格,假设所有产品在修改前的价格都是 10

\n\n

任意顺序 返回结果表。

\n\n

结果格式如下例所示。

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nProducts 表:\n+------------+-----------+-------------+\n| product_id | new_price | change_date |\n+------------+-----------+-------------+\n| 1          | 20        | 2019-08-14  |\n| 2          | 50        | 2019-08-14  |\n| 1          | 30        | 2019-08-15  |\n| 1          | 35        | 2019-08-16  |\n| 2          | 65        | 2019-08-17  |\n| 3          | 20        | 2019-08-18  |\n+------------+-----------+-------------+\n输出:\n+------------+-------+\n| product_id | price |\n+------------+-------+\n| 2          | 50    |\n| 1          | 35    |\n| 3          | 10    |\n+------------+-------+
\n", + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 149, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef price_at_given_date(products: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"24.7K\", \"totalSubmission\": \"44.2K\", \"totalAcceptedRaw\": 24690, \"totalSubmissionRaw\": 44223, \"acRate\": \"55.8%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Products\":[\"product_id\",\"new_price\",\"change_date\"]},\"rows\":{\"Products\":[[1,20,\"2019-08-14\"],[2,50,\"2019-08-14\"],[1,30,\"2019-08-15\"],[1,35,\"2019-08-16\"],[2,65,\"2019-08-17\"],[3,20,\"2019-08-18\"]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Products (product_id int, new_price int, change_date date)\"],\"mssql\":[\"Create table Products (product_id int, new_price int, change_date date)\"],\"oraclesql\":[\"Create table Products (product_id int, new_price int, change_date date)\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"],\"database\":true,\"name\":\"price_at_given_date\",\"pythondata\":[\"Products = pd.DataFrame([], columns=['product_id', 'new_price', 'change_date']).astype({'product_id':'Int64', 'new_price':'Int64', 'change_date':'datetime64[ns]'})\"],\"postgresql\":[\"\\nCreate table If Not Exists Products (product_id int, new_price int, change_date date)\"],\"database_schema\":{\"Products\":{\"product_id\":\"INT\",\"new_price\":\"INT\",\"change_date\":\"DATE\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Products (product_id int, new_price int, change_date date)", + "Truncate table Products", + "insert into Products (product_id, new_price, change_date) values ('1', '20', '2019-08-14')", + "insert into Products (product_id, new_price, change_date) values ('2', '50', '2019-08-14')", + "insert into Products (product_id, new_price, change_date) values ('1', '30', '2019-08-15')", + "insert into Products (product_id, new_price, change_date) values ('1', '35', '2019-08-16')", + "insert into Products (product_id, new_price, change_date) values ('2', '65', '2019-08-17')", + "insert into Products (product_id, new_price, change_date) values ('3', '20', '2019-08-18')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Products\":[\"product_id\",\"new_price\",\"change_date\"]},\"rows\":{\"Products\":[[1,20,\"2019-08-14\"],[2,50,\"2019-08-14\"],[1,30,\"2019-08-15\"],[1,35,\"2019-08-16\"],[2,65,\"2019-08-17\"],[3,20,\"2019-08-18\"]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/product-sales-analysis-i.json b/leetcode-cn/originData/product-sales-analysis-i.json new file mode 100644 index 00000000..53dd496a --- /dev/null +++ b/leetcode-cn/originData/product-sales-analysis-i.json @@ -0,0 +1,95 @@ +{ + "data": { + "question": { + "questionId": "1153", + "questionFrontendId": "1068", + "categoryTitle": "Database", + "boundTopicId": 7633, + "title": "Product Sales Analysis I", + "titleSlug": "product-sales-analysis-i", + "content": "

Table: Sales

\n\n
\n+-------------+-------+\n| Column Name | Type  |\n+-------------+-------+\n| sale_id     | int   |\n| product_id  | int   |\n| year        | int   |\n| quantity    | int   |\n| price       | int   |\n+-------------+-------+\n(sale_id, year) is the primary key (combination of columns with unique values) of this table.\nproduct_id is a foreign key (reference column) to Product table.\nEach row of this table shows a sale on the product product_id in a certain year.\nNote that the price is per unit.\n
\n\n

 

\n\n

Table: Product

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n+--------------+---------+\nproduct_id is the primary key (column with unique values) of this table.\nEach row of this table indicates the product name of each product.\n
\n\n

 

\n\n

Write a solution to report the product_name, year, and price for each sale_id in the Sales table.

\n\n

Return the resulting table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nSales table:\n+---------+------------+------+----------+-------+\n| sale_id | product_id | year | quantity | price |\n+---------+------------+------+----------+-------+ \n| 1       | 100        | 2008 | 10       | 5000  |\n| 2       | 100        | 2009 | 12       | 5000  |\n| 7       | 200        | 2011 | 15       | 9000  |\n+---------+------------+------+----------+-------+\nProduct table:\n+------------+--------------+\n| product_id | product_name |\n+------------+--------------+\n| 100        | Nokia        |\n| 200        | Apple        |\n| 300        | Samsung      |\n+------------+--------------+\nOutput: \n+--------------+-------+-------+\n| product_name | year  | price |\n+--------------+-------+-------+\n| Nokia        | 2008  | 5000  |\n| Nokia        | 2009  | 5000  |\n| Apple        | 2011  | 9000  |\n+--------------+-------+-------+\nExplanation: \nFrom sale_id = 1, we can conclude that Nokia was sold for 5000 in the year 2008.\nFrom sale_id = 2, we can conclude that Nokia was sold for 5000 in the year 2009.\nFrom sale_id = 7, we can conclude that Apple was sold for 9000 in the year 2011.\n
\n", + "translatedTitle": "产品销售分析 I", + "translatedContent": "

销售表 Sales

\n\n
\n+-------------+-------+\n| Column Name | Type  |\n+-------------+-------+\n| sale_id     | int   |\n| product_id  | int   |\n| year        | int   |\n| quantity    | int   |\n| price       | int   |\n+-------------+-------+\n(sale_id, year) 是销售表 Sales 的主键(具有唯一值的列的组合)。\nproduct_id 是关联到产品表 Product 的外键(reference 列)。\n该表的每一行显示 product_id 在某一年的销售情况。\n注意: price 表示每单位价格。\n
\n\n

产品表 Product

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n+--------------+---------+\nproduct_id 是表的主键(具有唯一值的列)。\n该表的每一行表示每种产品的产品名称。\n
\n\n

 

\n\n

编写解决方案,以获取 Sales 表中所有 sale_id 对应的 product_name 以及该产品的所有 year 和 price

\n\n

返回结果表 无顺序要求

\n\n

结果格式示例如下。

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nSales 表:\n+---------+------------+------+----------+-------+\n| sale_id | product_id | year | quantity | price |\n+---------+------------+------+----------+-------+ \n| 1       | 100        | 2008 | 10       | 5000  |\n| 2       | 100        | 2009 | 12       | 5000  |\n| 7       | 200        | 2011 | 15       | 9000  |\n+---------+------------+------+----------+-------+\nProduct 表:\n+------------+--------------+\n| product_id | product_name |\n+------------+--------------+\n| 100        | Nokia        |\n| 200        | Apple        |\n| 300        | Samsung      |\n+------------+--------------+\n输出:\n+--------------+-------+-------+\n| product_name | year  | price |\n+--------------+-------+-------+\n| Nokia        | 2008  | 5000  |\n| Nokia        | 2009  | 5000  |\n| Apple        | 2011  | 9000  |\n+--------------+-------+-------+\n
\n", + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 56, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef sales_analysis(sales: pd.DataFrame, product: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"54.1K\", \"totalSubmission\": \"61.9K\", \"totalAcceptedRaw\": 54130, \"totalSubmissionRaw\": 61868, \"acRate\": \"87.5%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Sales\":[\"sale_id\",\"product_id\",\"year\",\"quantity\",\"price\"],\"Product\":[\"product_id\",\"product_name\"]},\"rows\":{\"Sales\":[[1,100,2008,10,5000],[2,100,2009,12,5000],[7,200,2011,15,9000]],\"Product\":[[100,\"Nokia\"],[200,\"Apple\"],[300,\"Samsung\"]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Sales (sale_id int, product_id int, year int, quantity int, price int)\",\"Create table If Not Exists Product (product_id int, product_name varchar(10))\"],\"mssql\":[\"Create table Sales (sale_id int, product_id int, year int, quantity int, price int)\",\"Create table Product (product_id int, product_name varchar(10))\"],\"oraclesql\":[\"Create table Sales (sale_id int, product_id int, year int, quantity int, price int)\",\"Create table Product (product_id int, product_name varchar(10))\"],\"database\":true,\"name\":\"sales_analysis\",\"pythondata\":[\"Sales = pd.DataFrame([], columns=['sale_id', 'product_id', 'year', 'quantity', 'price']).astype({'sale_id':'Int64', 'product_id':'Int64', 'year':'Int64', 'quantity':'Int64', 'price':'Int64'})\",\"Product = pd.DataFrame([], columns=['product_id', 'product_name']).astype({'product_id':'Int64', 'product_name':'object'})\"],\"postgresql\":[\"Create table If Not Exists Sales (sale_id int, product_id int, year int, quantity int, price int)\\n\",\"Create table If Not Exists Product (product_id int, product_name varchar(10))\"],\"database_schema\":{\"Sales\":{\"sale_id\":\"INT\",\"product_id\":\"INT\",\"year\":\"INT\",\"quantity\":\"INT\",\"price\":\"INT\"},\"Product\":{\"product_id\":\"INT\",\"product_name\":\"VARCHAR(10)\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Sales (sale_id int, product_id int, year int, quantity int, price int)", + "Create table If Not Exists Product (product_id int, product_name varchar(10))", + "Truncate table Sales", + "insert into Sales (sale_id, product_id, year, quantity, price) values ('1', '100', '2008', '10', '5000')", + "insert into Sales (sale_id, product_id, year, quantity, price) values ('2', '100', '2009', '12', '5000')", + "insert into Sales (sale_id, product_id, year, quantity, price) values ('7', '200', '2011', '15', '9000')", + "Truncate table Product", + "insert into Product (product_id, product_name) values ('100', 'Nokia')", + "insert into Product (product_id, product_name) values ('200', 'Apple')", + "insert into Product (product_id, product_name) values ('300', 'Samsung')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Sales\":[\"sale_id\",\"product_id\",\"year\",\"quantity\",\"price\"],\"Product\":[\"product_id\",\"product_name\"]},\"rows\":{\"Sales\":[[1,100,2008,10,5000],[2,100,2009,12,5000],[7,200,2011,15,9000]],\"Product\":[[100,\"Nokia\"],[200,\"Apple\"],[300,\"Samsung\"]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/product-sales-analysis-iii.json b/leetcode-cn/originData/product-sales-analysis-iii.json new file mode 100644 index 00000000..caae47aa --- /dev/null +++ b/leetcode-cn/originData/product-sales-analysis-iii.json @@ -0,0 +1,95 @@ +{ + "data": { + "question": { + "questionId": "1155", + "questionFrontendId": "1070", + "categoryTitle": "Database", + "boundTopicId": 7635, + "title": "Product Sales Analysis III", + "titleSlug": "product-sales-analysis-iii", + "content": "

Table: Sales

\n\n
\n+-------------+-------+\n| Column Name | Type  |\n+-------------+-------+\n| sale_id     | int   |\n| product_id  | int   |\n| year        | int   |\n| quantity    | int   |\n| price       | int   |\n+-------------+-------+\n(sale_id, year) is the primary key (combination of columns with unique values) of this table.\nproduct_id is a foreign key (reference column) to Product table.\nEach row of this table shows a sale on the product product_id in a certain year.\nNote that the price is per unit.\n
\n\n

 

\n\n

Table: Product

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n+--------------+---------+\nproduct_id is the primary key (column with unique values) of this table.\nEach row of this table indicates the product name of each product.\n
\n\n

 

\n\n

Write a solution to select the product id, year, quantity, and price for the first year of every product sold.

\n\n

Return the resulting table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nSales table:\n+---------+------------+------+----------+-------+\n| sale_id | product_id | year | quantity | price |\n+---------+------------+------+----------+-------+ \n| 1       | 100        | 2008 | 10       | 5000  |\n| 2       | 100        | 2009 | 12       | 5000  |\n| 7       | 200        | 2011 | 15       | 9000  |\n+---------+------------+------+----------+-------+\nProduct table:\n+------------+--------------+\n| product_id | product_name |\n+------------+--------------+\n| 100        | Nokia        |\n| 200        | Apple        |\n| 300        | Samsung      |\n+------------+--------------+\nOutput: \n+------------+------------+----------+-------+\n| product_id | first_year | quantity | price |\n+------------+------------+----------+-------+ \n| 100        | 2008       | 10       | 5000  |\n| 200        | 2011       | 15       | 9000  |\n+------------+------------+----------+-------+\n
\n", + "translatedTitle": "产品销售分析 III", + "translatedContent": "

销售表 Sales

\n\n
\n+-------------+-------+\n| Column Name | Type  |\n+-------------+-------+\n| sale_id     | int   |\n| product_id  | int   |\n| year        | int   |\n| quantity    | int   |\n| price       | int   |\n+-------------+-------+\n(sale_id, year) 是这张表的主键(具有唯一值的列的组合)。\nproduct_id 是产品表的外键(reference 列)。\n这张表的每一行都表示:编号 product_id 的产品在某一年的销售额。\n请注意,价格是按每单位计的。\n
\n\n

 

\n\n

产品表 Product

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n+--------------+---------+\nproduct_id 是这张表的主键(具有唯一值的列)。\n这张表的每一行都标识:每个产品的 id 和 产品名称。
\n\n

 

\n\n

编写解决方案,选出每个售出过的产品 第一年 销售的 产品 id年份数量 价格

\n\n

结果表中的条目可以按 任意顺序 排列。

\n\n

结果格式如下例所示:

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nSales 表:\n+---------+------------+------+----------+-------+\n| sale_id | product_id | year | quantity | price |\n+---------+------------+------+----------+-------+ \n| 1       | 100        | 2008 | 10       | 5000  |\n| 2       | 100        | 2009 | 12       | 5000  |\n| 7       | 200        | 2011 | 15       | 9000  |\n+---------+------------+------+----------+-------+\nProduct 表:\n+------------+--------------+\n| product_id | product_name |\n+------------+--------------+\n| 100        | Nokia        |\n| 200        | Apple        |\n| 300        | Samsung      |\n+------------+--------------+\n输出:\n+------------+------------+----------+-------+\n| product_id | first_year | quantity | price |\n+------------+------------+----------+-------+ \n| 100        | 2008       | 10       | 5000  |\n| 200        | 2011       | 15       | 9000  |\n+------------+------------+----------+-------+
\n", + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 40, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef sales_analysis(sales: pd.DataFrame, product: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"20.4K\", \"totalSubmission\": \"43.5K\", \"totalAcceptedRaw\": 20400, \"totalSubmissionRaw\": 43512, \"acRate\": \"46.9%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Sales\":[\"sale_id\",\"product_id\",\"year\",\"quantity\",\"price\"],\"Product\":[\"product_id\",\"product_name\"]},\"rows\":{\"Sales\":[[1,100,2008,10,5000],[2,100,2009,12,5000],[7,200,2011,15,9000]],\"Product\":[[100,\"Nokia\"],[200,\"Apple\"],[300,\"Samsung\"]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Sales (sale_id int, product_id int, year int, quantity int, price int)\",\"Create table If Not Exists Product (product_id int, product_name varchar(10))\"],\"mssql\":[\"Create table Sales (sale_id int, product_id int, year int, quantity int, price int)\",\"Create table Product (product_id int, product_name varchar(10))\"],\"oraclesql\":[\"Create table Sales (sale_id int, product_id int, year int, quantity int, price int)\",\"Create table Product (product_id int, product_name varchar(10))\"],\"database\":true,\"name\":\"sales_analysis\",\"pythondata\":[\"Sales = pd.DataFrame([], columns=['sale_id', 'product_id', 'year', 'quantity', 'price']).astype({'sale_id':'Int64', 'product_id':'Int64', 'year':'Int64', 'quantity':'Int64', 'price':'Int64'})\",\"Product = pd.DataFrame([], columns=['product_id', 'product_name']).astype({'product_id':'Int64', 'product_name':'object'})\"],\"postgresql\":[\"Create table If Not Exists Sales (sale_id int, product_id int, year int, quantity int, price int)\\n\",\"Create table If Not Exists Product (product_id int, product_name varchar(10))\"],\"database_schema\":{\"Sales\":{\"sale_id\":\"INT\",\"product_id\":\"INT\",\"year\":\"INT\",\"quantity\":\"INT\",\"price\":\"INT\"},\"Product\":{\"product_id\":\"INT\",\"product_name\":\"VARCHAR(10)\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Sales (sale_id int, product_id int, year int, quantity int, price int)", + "Create table If Not Exists Product (product_id int, product_name varchar(10))", + "Truncate table Sales", + "insert into Sales (sale_id, product_id, year, quantity, price) values ('1', '100', '2008', '10', '5000')", + "insert into Sales (sale_id, product_id, year, quantity, price) values ('2', '100', '2009', '12', '5000')", + "insert into Sales (sale_id, product_id, year, quantity, price) values ('7', '200', '2011', '15', '9000')", + "Truncate table Product", + "insert into Product (product_id, product_name) values ('100', 'Nokia')", + "insert into Product (product_id, product_name) values ('200', 'Apple')", + "insert into Product (product_id, product_name) values ('300', 'Samsung')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Sales\":[\"sale_id\",\"product_id\",\"year\",\"quantity\",\"price\"],\"Product\":[\"product_id\",\"product_name\"]},\"rows\":{\"Sales\":[[1,100,2008,10,5000],[2,100,2009,12,5000],[7,200,2011,15,9000]],\"Product\":[[100,\"Nokia\"],[200,\"Apple\"],[300,\"Samsung\"]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/project-employees-i.json b/leetcode-cn/originData/project-employees-i.json new file mode 100644 index 00000000..485597aa --- /dev/null +++ b/leetcode-cn/originData/project-employees-i.json @@ -0,0 +1,98 @@ +{ + "data": { + "question": { + "questionId": "1161", + "questionFrontendId": "1075", + "categoryTitle": "Database", + "boundTopicId": 8825, + "title": "Project Employees I", + "titleSlug": "project-employees-i", + "content": "

Table: Project

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| project_id  | int     |\n| employee_id | int     |\n+-------------+---------+\n(project_id, employee_id) is the primary key of this table.\nemployee_id is a foreign key to Employee table.\nEach row of this table indicates that the employee with employee_id is working on the project with project_id.\n
\n\n

 

\n\n

Table: Employee

\n\n
\n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| employee_id      | int     |\n| name             | varchar |\n| experience_years | int     |\n+------------------+---------+\nemployee_id is the primary key of this table. It's guaranteed that experience_years is not NULL.\nEach row of this table contains information about one employee.\n
\n\n

 

\n\n

Write an SQL query that reports the average experience years of all the employees for each project, rounded to 2 digits.

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nProject table:\n+-------------+-------------+\n| project_id  | employee_id |\n+-------------+-------------+\n| 1           | 1           |\n| 1           | 2           |\n| 1           | 3           |\n| 2           | 1           |\n| 2           | 4           |\n+-------------+-------------+\nEmployee table:\n+-------------+--------+------------------+\n| employee_id | name   | experience_years |\n+-------------+--------+------------------+\n| 1           | Khaled | 3                |\n| 2           | Ali    | 2                |\n| 3           | John   | 1                |\n| 4           | Doe    | 2                |\n+-------------+--------+------------------+\nOutput: \n+-------------+---------------+\n| project_id  | average_years |\n+-------------+---------------+\n| 1           | 2.00          |\n| 2           | 2.50          |\n+-------------+---------------+\nExplanation: The average experience years for the first project is (3 + 2 + 1) / 3 = 2.00 and for the second project is (3 + 2) / 2 = 2.50\n
\n", + "translatedTitle": "项目员工 I", + "translatedContent": "

项目表 Project: 

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| project_id  | int     |\n| employee_id | int     |\n+-------------+---------+\n主键为 (project_id, employee_id)。\nemployee_id 是员工表 Employee 表的外键。\n
\n\n

员工表 Employee

\n\n
\n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| employee_id      | int     |\n| name             | varchar |\n| experience_years | int     |\n+------------------+---------+\n主键是 employee_id。\n
\n\n

 

\n\n

请写一个 SQL 语句,查询每一个项目中员工的 平均 工作年限,精确到小数点后两位

\n\n

查询结果的格式如下:

\n\n
\nProject 表:\n+-------------+-------------+\n| project_id  | employee_id |\n+-------------+-------------+\n| 1           | 1           |\n| 1           | 2           |\n| 1           | 3           |\n| 2           | 1           |\n| 2           | 4           |\n+-------------+-------------+\n\nEmployee 表:\n+-------------+--------+------------------+\n| employee_id | name   | experience_years |\n+-------------+--------+------------------+\n| 1           | Khaled | 3                |\n| 2           | Ali    | 2                |\n| 3           | John   | 1                |\n| 4           | Doe    | 2                |\n+-------------+--------+------------------+\n\nResult 表:\n+-------------+---------------+\n| project_id  | average_years |\n+-------------+---------------+\n| 1           | 2.00          |\n| 2           | 2.50          |\n+-------------+---------------+\n第一个项目中,员工的平均工作年限是 (3 + 2 + 1) / 3 = 2.00;第二个项目中,员工的平均工作年限是 (3 + 2) / 2 = 2.50\n
\n", + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 53, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef project_employees_i(project: pd.DataFrame, employee: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"35.7K\", \"totalSubmission\": \"52.8K\", \"totalAcceptedRaw\": 35706, \"totalSubmissionRaw\": 52791, \"acRate\": \"67.6%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Project\":[\"project_id\",\"employee_id\"],\"Employee\":[\"employee_id\",\"name\",\"experience_years\"]},\"rows\":{\"Project\":[[1,1],[1,2],[1,3],[2,1],[2,4]],\"Employee\":[[1,\"Khaled\",3],[2,\"Ali\",2],[3,\"John\",1],[4,\"Doe\",2]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Project (project_id int, employee_id int)\",\"Create table If Not Exists Employee (employee_id int, name varchar(10), experience_years int)\"],\"mssql\":[\"Create table Project (project_id int, employee_id int)\",\"Create table Employee (employee_id int, name varchar(10), experience_years int)\"],\"oraclesql\":[\"Create table Project (project_id int, employee_id int)\",\"Create table Employee (employee_id int, name varchar(10), experience_years int)\"],\"database\":true,\"name\":\"project_employees_i\",\"pythondata\":[\"Project = pd.DataFrame([], columns=['project_id', 'employee_id']).astype({'project_id':'Int64', 'employee_id':'Int64'})\",\"Employee = pd.DataFrame([], columns=['employee_id', 'name', 'experience_years']).astype({'employee_id':'Int64', 'name':'object', 'experience_years':'Int64'})\"],\"postgresql\":[\"Create table If Not Exists Project (project_id int, employee_id int)\",\"Create table If Not Exists Employee (employee_id int, name varchar(10), experience_years int)\"],\"database_schema\":{\"Project\":{\"project_id\":\"INT\",\"employee_id\":\"INT\"},\"Employee\":{\"employee_id\":\"INT\",\"name\":\"VARCHAR(10)\",\"experience_years\":\"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Project (project_id int, employee_id int)", + "Create table If Not Exists Employee (employee_id int, name varchar(10), experience_years int)", + "Truncate table Project", + "insert into Project (project_id, employee_id) values ('1', '1')", + "insert into Project (project_id, employee_id) values ('1', '2')", + "insert into Project (project_id, employee_id) values ('1', '3')", + "insert into Project (project_id, employee_id) values ('2', '1')", + "insert into Project (project_id, employee_id) values ('2', '4')", + "Truncate table Employee", + "insert into Employee (employee_id, name, experience_years) values ('1', 'Khaled', '3')", + "insert into Employee (employee_id, name, experience_years) values ('2', 'Ali', '2')", + "insert into Employee (employee_id, name, experience_years) values ('3', 'John', '1')", + "insert into Employee (employee_id, name, experience_years) values ('4', 'Doe', '2')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Project\":[\"project_id\",\"employee_id\"],\"Employee\":[\"employee_id\",\"name\",\"experience_years\"]},\"rows\":{\"Project\":[[1,1],[1,2],[1,3],[2,1],[2,4]],\"Employee\":[[1,\"Khaled\",3],[2,\"Ali\",2],[3,\"John\",1],[4,\"Doe\",2]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/queries-quality-and-percentage.json b/leetcode-cn/originData/queries-quality-and-percentage.json new file mode 100644 index 00000000..5873cd99 --- /dev/null +++ b/leetcode-cn/originData/queries-quality-and-percentage.json @@ -0,0 +1,93 @@ +{ + "data": { + "question": { + "questionId": "1338", + "questionFrontendId": "1211", + "categoryTitle": "Database", + "boundTopicId": 33172, + "title": "Queries Quality and Percentage", + "titleSlug": "queries-quality-and-percentage", + "content": "

Table: Queries

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| query_name  | varchar |\n| result      | varchar |\n| position    | int     |\n| rating      | int     |\n+-------------+---------+\nThis table may have duplicate rows.\nThis table contains information collected from some queries on a database.\nThe position column has a value from 1 to 500.\nThe rating column has a value from 1 to 5. Query with rating less than 3 is a poor query.\n
\n\n

 

\n\n

We define query quality as:

\n\n
\n

The average of the ratio between query rating and its position.

\n
\n\n

We also define poor query percentage as:

\n\n
\n

The percentage of all queries with rating less than 3.

\n
\n\n

Write a solution to find each query_name, the quality and poor_query_percentage.

\n\n

Both quality and poor_query_percentage should be rounded to 2 decimal places.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nQueries table:\n+------------+-------------------+----------+--------+\n| query_name | result            | position | rating |\n+------------+-------------------+----------+--------+\n| Dog        | Golden Retriever  | 1        | 5      |\n| Dog        | German Shepherd   | 2        | 5      |\n| Dog        | Mule              | 200      | 1      |\n| Cat        | Shirazi           | 5        | 2      |\n| Cat        | Siamese           | 3        | 3      |\n| Cat        | Sphynx            | 7        | 4      |\n+------------+-------------------+----------+--------+\nOutput: \n+------------+---------+-----------------------+\n| query_name | quality | poor_query_percentage |\n+------------+---------+-----------------------+\n| Dog        | 2.50    | 33.33                 |\n| Cat        | 0.66    | 33.33                 |\n+------------+---------+-----------------------+\nExplanation: \nDog queries quality is ((5 / 1) + (5 / 2) + (1 / 200)) / 3 = 2.50\nDog queries poor_ query_percentage is (1 / 3) * 100 = 33.33\n\nCat queries quality equals ((2 / 5) + (3 / 3) + (4 / 7)) / 3 = 0.66\nCat queries poor_ query_percentage is (1 / 3) * 100 = 33.33\n
\n", + "translatedTitle": "查询结果的质量和占比", + "translatedContent": "

Queries 表: 

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| query_name  | varchar |\n| result      | varchar |\n| position    | int     |\n| rating      | int     |\n+-------------+---------+\n此表可能有重复的行。\n此表包含了一些从数据库中收集的查询信息。\n“位置”(position)列的值为 1500 。\n“评分”(rating)列的值为 15 。评分小于 3 的查询被定义为质量很差的查询。\n
\n\n

 

\n\n

将查询结果的质量 quality 定义为:

\n\n
\n

各查询结果的评分与其位置之间比率的平均值。

\n
\n\n

将劣质查询百分比 poor_query_percentage 为:

\n\n
\n

评分小于 3 的查询结果占全部查询结果的百分比。

\n
\n\n

编写解决方案,找出每次的 query_name 、 quality 和 poor_query_percentage

\n\n

quality 和 poor_query_percentage 都应 四舍五入到小数点后两位

\n\n

任意顺序 返回结果表。

\n\n

结果格式如下所示:

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nQueries table:\n+------------+-------------------+----------+--------+\n| query_name | result            | position | rating |\n+------------+-------------------+----------+--------+\n| Dog        | Golden Retriever  | 1        | 5      |\n| Dog        | German Shepherd   | 2        | 5      |\n| Dog        | Mule              | 200      | 1      |\n| Cat        | Shirazi           | 5        | 2      |\n| Cat        | Siamese           | 3        | 3      |\n| Cat        | Sphynx            | 7        | 4      |\n+------------+-------------------+----------+--------+\n输出:\n+------------+---------+-----------------------+\n| query_name | quality | poor_query_percentage |\n+------------+---------+-----------------------+\n| Dog        | 2.50    | 33.33                 |\n| Cat        | 0.66    | 33.33                 |\n+------------+---------+-----------------------+\n解释:\nDog 查询结果的质量为 ((5 / 1) + (5 / 2) + (1 / 200)) / 3 = 2.50\nDog 查询结果的劣质查询百分比为 (1 / 3) * 100 = 33.33\n\nCat 查询结果的质量为 ((2 / 5) + (3 / 3) + (4 / 7)) / 3 = 0.66\nCat 查询结果的劣质查询百分比为 (1 / 3) * 100 = 33.33\n
\n", + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 78, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef queries_stats(queries: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"32.4K\", \"totalSubmission\": \"49.5K\", \"totalAcceptedRaw\": 32402, \"totalSubmissionRaw\": 49549, \"acRate\": \"65.4%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Queries\":[\"query_name\",\"result\",\"position\",\"rating\"]},\"rows\":{\"Queries\":[[\"Dog\",\"Golden Retriever\",1,5],[\"Dog\",\"German Shepherd\",2,5],[\"Dog\",\"Mule\",200,1],[\"Cat\",\"Shirazi\",5,2],[\"Cat\",\"Siamese\",3,3],[\"Cat\",\"Sphynx\",7,4]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Queries (query_name varchar(30), result varchar(50), position int, rating int)\"],\"mssql\":[\"create table Queries (query_name varchar(30), result varchar(50), position int, rating int)\"],\"oraclesql\":[\"create table Queries (query_name varchar(30), result varchar(50), position int, rating int)\"],\"database\":true,\"name\":\"queries_stats\",\"pythondata\":[\"Queries = pd.DataFrame([], columns=['query_name', 'result', 'position', 'rating']).astype({'query_name':'object', 'result':'object', 'position':'Int64', 'rating':'Int64'})\"],\"postgresql\":[\"\\nCreate table If Not Exists Queries (query_name varchar(30), result varchar(50), position int, rating int)\"],\"database_schema\":{\"Queries\":{\"query_name\":\"VARCHAR(30)\",\"result\":\"VARCHAR(50)\",\"position\":\"INT\",\"rating\":\"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Queries (query_name varchar(30), result varchar(50), position int, rating int)", + "Truncate table Queries", + "insert into Queries (query_name, result, position, rating) values ('Dog', 'Golden Retriever', '1', '5')", + "insert into Queries (query_name, result, position, rating) values ('Dog', 'German Shepherd', '2', '5')", + "insert into Queries (query_name, result, position, rating) values ('Dog', 'Mule', '200', '1')", + "insert into Queries (query_name, result, position, rating) values ('Cat', 'Shirazi', '5', '2')", + "insert into Queries (query_name, result, position, rating) values ('Cat', 'Siamese', '3', '3')", + "insert into Queries (query_name, result, position, rating) values ('Cat', 'Sphynx', '7', '4')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Queries\":[\"query_name\",\"result\",\"position\",\"rating\"]},\"rows\":{\"Queries\":[[\"Dog\",\"Golden Retriever\",1,5],[\"Dog\",\"German Shepherd\",2,5],[\"Dog\",\"Mule\",200,1],[\"Cat\",\"Shirazi\",5,2],[\"Cat\",\"Siamese\",3,3],[\"Cat\",\"Sphynx\",7,4]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/replace-employee-id-with-the-unique-identifier.json b/leetcode-cn/originData/replace-employee-id-with-the-unique-identifier.json new file mode 100644 index 00000000..5de7760a --- /dev/null +++ b/leetcode-cn/originData/replace-employee-id-with-the-unique-identifier.json @@ -0,0 +1,97 @@ +{ + "data": { + "question": { + "questionId": "1509", + "questionFrontendId": "1378", + "categoryTitle": "Database", + "boundTopicId": 145923, + "title": "Replace Employee ID With The Unique Identifier", + "titleSlug": "replace-employee-id-with-the-unique-identifier", + "content": "

Table: Employees

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\nid is the primary key (column with unique values) for this table.\nEach row of this table contains the id and the name of an employee in a company.\n
\n\n

 

\n\n

Table: EmployeeUNI

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| unique_id     | int     |\n+---------------+---------+\n(id, unique_id) is the primary key (combination of columns with unique values) for this table.\nEach row of this table contains the id and the corresponding unique id of an employee in the company.\n
\n\n

 

\n\n

Write a solution to show the unique ID of each user, If a user does not have a unique ID replace just show null.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nEmployees table:\n+----+----------+\n| id | name     |\n+----+----------+\n| 1  | Alice    |\n| 7  | Bob      |\n| 11 | Meir     |\n| 90 | Winston  |\n| 3  | Jonathan |\n+----+----------+\nEmployeeUNI table:\n+----+-----------+\n| id | unique_id |\n+----+-----------+\n| 3  | 1         |\n| 11 | 2         |\n| 90 | 3         |\n+----+-----------+\nOutput: \n+-----------+----------+\n| unique_id | name     |\n+-----------+----------+\n| null      | Alice    |\n| null      | Bob      |\n| 2         | Meir     |\n| 3         | Winston  |\n| 1         | Jonathan |\n+-----------+----------+\nExplanation: \nAlice and Bob do not have a unique ID, We will show null instead.\nThe unique ID of Meir is 2.\nThe unique ID of Winston is 3.\nThe unique ID of Jonathan is 1.\n
\n", + "translatedTitle": "使用唯一标识码替换员工ID", + "translatedContent": "

Employees 表:

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\n在 SQL 中,id 是这张表的主键。\n这张表的每一行分别代表了某公司其中一位员工的名字和 ID 。\n
\n\n

 

\n\n

EmployeeUNI 表:

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| unique_id     | int     |\n+---------------+---------+\n在 SQL 中,(id, unique_id) 是这张表的主键。\n这张表的每一行包含了该公司某位员工的 ID 和他的唯一标识码(unique ID)。\n
\n\n

 

\n\n

展示每位用户的 唯一标识码(unique ID );如果某位员工没有唯一标识码,使用 null 填充即可。

\n\n

你可以以 任意 顺序返回结果表。

\n\n

返回结果的格式如下例所示。

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nEmployees 表:\n+----+----------+\n| id | name     |\n+----+----------+\n| 1  | Alice    |\n| 7  | Bob      |\n| 11 | Meir     |\n| 90 | Winston  |\n| 3  | Jonathan |\n+----+----------+\nEmployeeUNI 表:\n+----+-----------+\n| id | unique_id |\n+----+-----------+\n| 3  | 1         |\n| 11 | 2         |\n| 90 | 3         |\n+----+-----------+\n输出:\n+-----------+----------+\n| unique_id | name     |\n+-----------+----------+\n| null      | Alice    |\n| null      | Bob      |\n| 2         | Meir     |\n| 3         | Winston  |\n| 1         | Jonathan |\n+-----------+----------+\n解释:\nAlice and Bob 没有唯一标识码, 因此我们使用 null 替代。\nMeir 的唯一标识码是 2 。\nWinston 的唯一标识码是 3 。\nJonathan 唯一标识码是 1 。
\n", + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 60, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef replace_employee_id(employees: pd.DataFrame, employee_uni: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"39.9K\", \"totalSubmission\": \"48.2K\", \"totalAcceptedRaw\": 39947, \"totalSubmissionRaw\": 48216, \"acRate\": \"82.9%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Employees\":[\"id\",\"name\"],\"EmployeeUNI\":[\"id\",\"unique_id\"]},\"rows\":{\"Employees\":[[1,\"Alice\"],[7,\"Bob\"],[11,\"Meir\"],[90,\"Winston\"],[3,\"Jonathan\"]],\"EmployeeUNI\":[[3,1],[11,2],[90,3]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Employees (id int, name varchar(20))\",\"Create table If Not Exists EmployeeUNI (id int, unique_id int)\"],\"mssql\":[\"Create table Employees (id int, name varchar(20))\",\"Create table EmployeeUNI (id int, unique_id int)\"],\"oraclesql\":[\"Create table Employees (id int, name varchar(20))\",\"Create table EmployeeUNI (id int, unique_id int)\"],\"database\":true,\"name\":\"replace_employee_id\",\"pythondata\":[\"Employees = pd.DataFrame([], columns=['id', 'name']).astype({'id':'int64', 'name':'object'})\",\"EmployeeUNI = pd.DataFrame([], columns=['id', 'unique_id']).astype({'id':'int64', 'unique_id':'int64'})\"],\"postgresql\":[\"\\nCreate table If Not Exists Employees (id int, name varchar(20))\\n\",\"Create table If Not Exists EmployeeUNI (id int, unique_id int)\"],\"database_schema\":{\"Employees\":{\"id\":\"INT\",\"name\":\"VARCHAR(20)\"},\"EmployeeUNI\":{\"id\":\"INT\",\"unique_id\":\"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Employees (id int, name varchar(20))", + "Create table If Not Exists EmployeeUNI (id int, unique_id int)", + "Truncate table Employees", + "insert into Employees (id, name) values ('1', 'Alice')", + "insert into Employees (id, name) values ('7', 'Bob')", + "insert into Employees (id, name) values ('11', 'Meir')", + "insert into Employees (id, name) values ('90', 'Winston')", + "insert into Employees (id, name) values ('3', 'Jonathan')", + "Truncate table EmployeeUNI", + "insert into EmployeeUNI (id, unique_id) values ('3', '1')", + "insert into EmployeeUNI (id, unique_id) values ('11', '2')", + "insert into EmployeeUNI (id, unique_id) values ('90', '3')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Employees\":[\"id\",\"name\"],\"EmployeeUNI\":[\"id\",\"unique_id\"]},\"rows\":{\"Employees\":[[1,\"Alice\"],[7,\"Bob\"],[11,\"Meir\"],[90,\"Winston\"],[3,\"Jonathan\"]],\"EmployeeUNI\":[[3,1],[11,2],[90,3]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/restaurant-growth.json b/leetcode-cn/originData/restaurant-growth.json new file mode 100644 index 00000000..1e39cfe7 --- /dev/null +++ b/leetcode-cn/originData/restaurant-growth.json @@ -0,0 +1,98 @@ +{ + "data": { + "question": { + "questionId": "1452", + "questionFrontendId": "1321", + "categoryTitle": "Database", + "boundTopicId": 74822, + "title": "Restaurant Growth", + "titleSlug": "restaurant-growth", + "content": "

Table: Customer

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| name          | varchar |\n| visited_on    | date    |\n| amount        | int     |\n+---------------+---------+\nIn SQL,(customer_id, visited_on) is the primary key for this table.\nThis table contains data about customer transactions in a restaurant.\nvisited_on is the date on which the customer with ID (customer_id) has visited the restaurant.\namount is the total paid by a customer.\n
\n\n

 

\n\n

You are the restaurant owner and you want to analyze a possible expansion (there will be at least one customer every day).

\n\n

Compute the moving average of how much the customer paid in a seven days window (i.e., current day + 6 days before). average_amount should be rounded to two decimal places.

\n\n

Return the result table ordered by visited_on in ascending order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nCustomer table:\n+-------------+--------------+--------------+-------------+\n| customer_id | name         | visited_on   | amount      |\n+-------------+--------------+--------------+-------------+\n| 1           | Jhon         | 2019-01-01   | 100         |\n| 2           | Daniel       | 2019-01-02   | 110         |\n| 3           | Jade         | 2019-01-03   | 120         |\n| 4           | Khaled       | 2019-01-04   | 130         |\n| 5           | Winston      | 2019-01-05   | 110         | \n| 6           | Elvis        | 2019-01-06   | 140         | \n| 7           | Anna         | 2019-01-07   | 150         |\n| 8           | Maria        | 2019-01-08   | 80          |\n| 9           | Jaze         | 2019-01-09   | 110         | \n| 1           | Jhon         | 2019-01-10   | 130         | \n| 3           | Jade         | 2019-01-10   | 150         | \n+-------------+--------------+--------------+-------------+\nOutput: \n+--------------+--------------+----------------+\n| visited_on   | amount       | average_amount |\n+--------------+--------------+----------------+\n| 2019-01-07   | 860          | 122.86         |\n| 2019-01-08   | 840          | 120            |\n| 2019-01-09   | 840          | 120            |\n| 2019-01-10   | 1000         | 142.86         |\n+--------------+--------------+----------------+\nExplanation: \n1st moving average from 2019-01-01 to 2019-01-07 has an average_amount of (100 + 110 + 120 + 130 + 110 + 140 + 150)/7 = 122.86\n2nd moving average from 2019-01-02 to 2019-01-08 has an average_amount of (110 + 120 + 130 + 110 + 140 + 150 + 80)/7 = 120\n3rd moving average from 2019-01-03 to 2019-01-09 has an average_amount of (120 + 130 + 110 + 140 + 150 + 80 + 110)/7 = 120\n4th moving average from 2019-01-04 to 2019-01-10 has an average_amount of (130 + 110 + 140 + 150 + 80 + 110 + 130 + 150)/7 = 142.86\n
\n", + "translatedTitle": "餐馆营业额变化增长", + "translatedContent": "

表: Customer

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| name          | varchar |\n| visited_on    | date    |\n| amount        | int     |\n+---------------+---------+\n在 SQL 中,(customer_id, visited_on) 是该表的主键。\n该表包含一家餐馆的顾客交易数据。\nvisited_on 表示 (customer_id) 的顾客在 visited_on 那天访问了餐馆。\namount 是一个顾客某一天的消费总额。\n
\n\n

 

\n\n

你是餐馆的老板,现在你想分析一下可能的营业额变化增长(每天至少有一位顾客)。

\n\n

计算以 7 天(某日期 + 该日期前的 6 天)为一个时间段的顾客消费平均值。average_amount 要 保留两位小数。

\n\n

结果按 visited_on 升序排序

\n\n

返回结果格式的例子如下。

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nCustomer 表:\n+-------------+--------------+--------------+-------------+\n| customer_id | name         | visited_on   | amount      |\n+-------------+--------------+--------------+-------------+\n| 1           | Jhon         | 2019-01-01   | 100         |\n| 2           | Daniel       | 2019-01-02   | 110         |\n| 3           | Jade         | 2019-01-03   | 120         |\n| 4           | Khaled       | 2019-01-04   | 130         |\n| 5           | Winston      | 2019-01-05   | 110         | \n| 6           | Elvis        | 2019-01-06   | 140         | \n| 7           | Anna         | 2019-01-07   | 150         |\n| 8           | Maria        | 2019-01-08   | 80          |\n| 9           | Jaze         | 2019-01-09   | 110         | \n| 1           | Jhon         | 2019-01-10   | 130         | \n| 3           | Jade         | 2019-01-10   | 150         | \n+-------------+--------------+--------------+-------------+\n输出:\n+--------------+--------------+----------------+\n| visited_on   | amount       | average_amount |\n+--------------+--------------+----------------+\n| 2019-01-07   | 860          | 122.86         |\n| 2019-01-08   | 840          | 120            |\n| 2019-01-09   | 840          | 120            |\n| 2019-01-10   | 1000         | 142.86         |\n+--------------+--------------+----------------+\n解释:\n第一个七天消费平均值从 2019-01-01 到 2019-01-07 是restaurant-growth/restaurant-growth/ (100 + 110 + 120 + 130 + 110 + 140 + 150)/7 = 122.86\n第二个七天消费平均值从 2019-01-02 到 2019-01-08 是 (110 + 120 + 130 + 110 + 140 + 150 + 80)/7 = 120\n第三个七天消费平均值从 2019-01-03 到 2019-01-09 是 (120 + 130 + 110 + 140 + 150 + 80 + 110)/7 = 120\n第四个七天消费平均值从 2019-01-04 到 2019-01-10 是 (130 + 110 + 140 + 150 + 80 + 110 + 130 + 150)/7 = 142.86
\n", + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 151, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef restaurant_growth(customer: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"18.7K\", \"totalSubmission\": \"35.8K\", \"totalAcceptedRaw\": 18737, \"totalSubmissionRaw\": 35843, \"acRate\": \"52.3%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Customer\":[\"customer_id\",\"name\",\"visited_on\",\"amount\"]},\"rows\":{\"Customer\":[[1,\"Jhon\",\"2019-01-01\",100],[2,\"Daniel\",\"2019-01-02\",110],[3,\"Jade\",\"2019-01-03\",120],[4,\"Khaled\",\"2019-01-04\",130],[5,\"Winston\",\"2019-01-05\",110],[6,\"Elvis\",\"2019-01-06\",140],[7,\"Anna\",\"2019-01-07\",150],[8,\"Maria\",\"2019-01-08\",80],[9,\"Jaze\",\"2019-01-09\",110],[1,\"Jhon\",\"2019-01-10\",130],[3,\"Jade\",\"2019-01-10\",150]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Customer (customer_id int, name varchar(20), visited_on date, amount int)\"],\"mssql\":[\"Create table Customer (customer_id int, name varchar(20), visited_on date, amount int)\"],\"oraclesql\":[\"Create table Customer (customer_id int, name varchar(20), visited_on date, amount int)\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"],\"database\":true,\"name\":\"restaurant_growth\",\"pythondata\":[\"Customer = pd.DataFrame([], columns=['customer_id', 'name', 'visited_on', 'amount']).astype({'customer_id':'Int64', 'name':'object', 'visited_on':'datetime64[ns]', 'amount':'Int64'})\"],\"postgresql\":[\"\\nCreate table If Not Exists Customer (customer_id int, name varchar(20), visited_on date, amount int)\"],\"database_schema\":{\"Customer\":{\"customer_id\":\"INT\",\"name\":\"VARCHAR(20)\",\"visited_on\":\"DATE\",\"amount\":\"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Customer (customer_id int, name varchar(20), visited_on date, amount int)", + "Truncate table Customer", + "insert into Customer (customer_id, name, visited_on, amount) values ('1', 'Jhon', '2019-01-01', '100')", + "insert into Customer (customer_id, name, visited_on, amount) values ('2', 'Daniel', '2019-01-02', '110')", + "insert into Customer (customer_id, name, visited_on, amount) values ('3', 'Jade', '2019-01-03', '120')", + "insert into Customer (customer_id, name, visited_on, amount) values ('4', 'Khaled', '2019-01-04', '130')", + "insert into Customer (customer_id, name, visited_on, amount) values ('5', 'Winston', '2019-01-05', '110')", + "insert into Customer (customer_id, name, visited_on, amount) values ('6', 'Elvis', '2019-01-06', '140')", + "insert into Customer (customer_id, name, visited_on, amount) values ('7', 'Anna', '2019-01-07', '150')", + "insert into Customer (customer_id, name, visited_on, amount) values ('8', 'Maria', '2019-01-08', '80')", + "insert into Customer (customer_id, name, visited_on, amount) values ('9', 'Jaze', '2019-01-09', '110')", + "insert into Customer (customer_id, name, visited_on, amount) values ('1', 'Jhon', '2019-01-10', '130')", + "insert into Customer (customer_id, name, visited_on, amount) values ('3', 'Jade', '2019-01-10', '150')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Customer\":[\"customer_id\",\"name\",\"visited_on\",\"amount\"]},\"rows\":{\"Customer\":[[1,\"Jhon\",\"2019-01-01\",100],[2,\"Daniel\",\"2019-01-02\",110],[3,\"Jade\",\"2019-01-03\",120],[4,\"Khaled\",\"2019-01-04\",130],[5,\"Winston\",\"2019-01-05\",110],[6,\"Elvis\",\"2019-01-06\",140],[7,\"Anna\",\"2019-01-07\",150],[8,\"Maria\",\"2019-01-08\",80],[9,\"Jaze\",\"2019-01-09\",110],[1,\"Jhon\",\"2019-01-10\",130],[3,\"Jade\",\"2019-01-10\",150]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/students-and-examinations.json b/leetcode-cn/originData/students-and-examinations.json new file mode 100644 index 00000000..9722fe24 --- /dev/null +++ b/leetcode-cn/originData/students-and-examinations.json @@ -0,0 +1,109 @@ +{ + "data": { + "question": { + "questionId": "1415", + "questionFrontendId": "1280", + "categoryTitle": "Database", + "boundTopicId": 51351, + "title": "Students and Examinations", + "titleSlug": "students-and-examinations", + "content": "

Table: Students

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| student_id    | int     |\n| student_name  | varchar |\n+---------------+---------+\nstudent_id is the primary key (column with unique values) for this table.\nEach row of this table contains the ID and the name of one student in the school.\n
\n\n

 

\n\n

Table: Subjects

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| subject_name | varchar |\n+--------------+---------+\nsubject_name is the primary key (column with unique values) for this table.\nEach row of this table contains the name of one subject in the school.\n
\n\n

 

\n\n

Table: Examinations

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| student_id   | int     |\n| subject_name | varchar |\n+--------------+---------+\nThere is no primary key (column with unique values) for this table. It may contain duplicates.\nEach student from the Students table takes every course from the Subjects table.\nEach row of this table indicates that a student with ID student_id attended the exam of subject_name.\n
\n\n

 

\n\n

Write a solution to find the number of times each student attended each exam.

\n\n

Return the result table ordered by student_id and subject_name.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nStudents table:\n+------------+--------------+\n| student_id | student_name |\n+------------+--------------+\n| 1          | Alice        |\n| 2          | Bob          |\n| 13         | John         |\n| 6          | Alex         |\n+------------+--------------+\nSubjects table:\n+--------------+\n| subject_name |\n+--------------+\n| Math         |\n| Physics      |\n| Programming  |\n+--------------+\nExaminations table:\n+------------+--------------+\n| student_id | subject_name |\n+------------+--------------+\n| 1          | Math         |\n| 1          | Physics      |\n| 1          | Programming  |\n| 2          | Programming  |\n| 1          | Physics      |\n| 1          | Math         |\n| 13         | Math         |\n| 13         | Programming  |\n| 13         | Physics      |\n| 2          | Math         |\n| 1          | Math         |\n+------------+--------------+\nOutput: \n+------------+--------------+--------------+----------------+\n| student_id | student_name | subject_name | attended_exams |\n+------------+--------------+--------------+----------------+\n| 1          | Alice        | Math         | 3              |\n| 1          | Alice        | Physics      | 2              |\n| 1          | Alice        | Programming  | 1              |\n| 2          | Bob          | Math         | 1              |\n| 2          | Bob          | Physics      | 0              |\n| 2          | Bob          | Programming  | 1              |\n| 6          | Alex         | Math         | 0              |\n| 6          | Alex         | Physics      | 0              |\n| 6          | Alex         | Programming  | 0              |\n| 13         | John         | Math         | 1              |\n| 13         | John         | Physics      | 1              |\n| 13         | John         | Programming  | 1              |\n+------------+--------------+--------------+----------------+\nExplanation: \nThe result table should contain all students and all subjects.\nAlice attended the Math exam 3 times, the Physics exam 2 times, and the Programming exam 1 time.\nBob attended the Math exam 1 time, the Programming exam 1 time, and did not attend the Physics exam.\nAlex did not attend any exams.\nJohn attended the Math exam 1 time, the Physics exam 1 time, and the Programming exam 1 time.\n
\n", + "translatedTitle": "学生们参加各科测试的次数", + "translatedContent": "

学生表: Students

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| student_id    | int     |\n| student_name  | varchar |\n+---------------+---------+\n在 SQL 中,主键为 student_id(学生ID)。\n该表内的每一行都记录有学校一名学生的信息。\n
\n\n

 

\n\n

科目表: Subjects

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| subject_name | varchar |\n+--------------+---------+\n在 SQL 中,主键为 subject_name(科目名称)。\n每一行记录学校的一门科目名称。\n
\n\n

 

\n\n

考试表: Examinations

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| student_id   | int     |\n| subject_name | varchar |\n+--------------+---------+\n这个表可能包含重复数据(换句话说,在 SQL 中,这个表没有主键)。\n学生表里的一个学生修读科目表里的每一门科目。\n这张考试表的每一行记录就表示学生表里的某个学生参加了一次科目表里某门科目的测试。\n
\n\n

 

\n\n

查询出每个学生参加每一门科目测试的次数,结果按 student_idsubject_name 排序。

\n\n

查询结构格式如下所示。

\n\n

 

\n\n

示例 1:

\n\n
\n输入:\nStudents table:\n+------------+--------------+\n| student_id | student_name |\n+------------+--------------+\n| 1          | Alice        |\n| 2          | Bob          |\n| 13         | John         |\n| 6          | Alex         |\n+------------+--------------+\nSubjects table:\n+--------------+\n| subject_name |\n+--------------+\n| Math         |\n| Physics      |\n| Programming  |\n+--------------+\nExaminations table:\n+------------+--------------+\n| student_id | subject_name |\n+------------+--------------+\n| 1          | Math         |\n| 1          | Physics      |\n| 1          | Programming  |\n| 2          | Programming  |\n| 1          | Physics      |\n| 1          | Math         |\n| 13         | Math         |\n| 13         | Programming  |\n| 13         | Physics      |\n| 2          | Math         |\n| 1          | Math         |\n+------------+--------------+\n输出:\n+------------+--------------+--------------+----------------+\n| student_id | student_name | subject_name | attended_exams |\n+------------+--------------+--------------+----------------+\n| 1          | Alice        | Math         | 3              |\n| 1          | Alice        | Physics      | 2              |\n| 1          | Alice        | Programming  | 1              |\n| 2          | Bob          | Math         | 1              |\n| 2          | Bob          | Physics      | 0              |\n| 2          | Bob          | Programming  | 1              |\n| 6          | Alex         | Math         | 0              |\n| 6          | Alex         | Physics      | 0              |\n| 6          | Alex         | Programming  | 0              |\n| 13         | John         | Math         | 1              |\n| 13         | John         | Physics      | 1              |\n| 13         | John         | Programming  | 1              |\n+------------+--------------+--------------+----------------+\n解释:\n结果表需包含所有学生和所有科目(即便测试次数为0):\nAlice 参加了 3 次数学测试, 2 次物理测试,以及 1 次编程测试;\nBob 参加了 1 次数学测试, 1 次编程测试,没有参加物理测试;\nAlex 啥测试都没参加;\nJohn  参加了数学、物理、编程测试各 1 次。\n
\n", + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 220, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef students_and_examinations(students: pd.DataFrame, subjects: pd.DataFrame, examinations: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"36K\", \"totalSubmission\": \"72.6K\", \"totalAcceptedRaw\": 35954, \"totalSubmissionRaw\": 72621, \"acRate\": \"49.5%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Students\":[\"student_id\",\"student_name\"],\"Subjects\":[\"subject_name\"],\"Examinations\":[\"student_id\",\"subject_name\"]},\"rows\":{\"Students\":[[1,\"Alice\"],[2,\"Bob\"],[13,\"John\"],[6,\"Alex\"]],\"Subjects\":[[\"Math\"],[\"Physics\"],[\"Programming\"]],\"Examinations\":[[1,\"Math\"],[1,\"Physics\"],[1,\"Programming\"],[2,\"Programming\"],[1,\"Physics\"],[1,\"Math\"],[13,\"Math\"],[13,\"Programming\"],[13,\"Physics\"],[2,\"Math\"],[1,\"Math\"]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Students (student_id int, student_name varchar(20))\",\"Create table If Not Exists Subjects (subject_name varchar(20))\",\"Create table If Not Exists Examinations (student_id int, subject_name varchar(20))\"],\"mssql\":[\"Create table Students (student_id int, student_name varchar(20))\",\"Create table Subjects (subject_name varchar(20))\",\"Create table Examinations (student_id int, subject_name varchar(20))\"],\"oraclesql\":[\"Create table Students (student_id int, student_name varchar(20))\\n\",\"Create table Subjects (subject_name varchar(20))\\n\",\"Create table Examinations (student_id int, subject_name varchar(20))\"],\"database\":true,\"name\":\"students_and_examinations\",\"pythondata\":[\"Students = pd.DataFrame([], columns=['student_id', 'student_name']).astype({'student_id':'Int64', 'student_name':'object'})\",\"Subjects = pd.DataFrame([], columns=['subject_name']).astype({'subject_name':'object'})\",\"Examinations = pd.DataFrame([], columns=['student_id', 'subject_name']).astype({'student_id':'Int64', 'subject_name':'object'})\"],\"manual\":false,\"postgresql\":[\"\\nCreate table If Not Exists Students (student_id int, student_name varchar(20))\\n\",\"Create table If Not Exists Subjects (subject_name varchar(20))\",\"Create table If Not Exists Examinations (student_id int, subject_name varchar(20))\"],\"database_schema\":{\"Students\":{\"student_id\":\"INT\",\"student_name\":\"VARCHAR(20)\"},\"Subjects\":{\"subject_name\":\"VARCHAR(20)\"},\"Examinations\":{\"student_id\":\"INT\",\"subject_name\":\"VARCHAR(20)\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Students (student_id int, student_name varchar(20))", + "Create table If Not Exists Subjects (subject_name varchar(20))", + "Create table If Not Exists Examinations (student_id int, subject_name varchar(20))", + "Truncate table Students", + "insert into Students (student_id, student_name) values ('1', 'Alice')", + "insert into Students (student_id, student_name) values ('2', 'Bob')", + "insert into Students (student_id, student_name) values ('13', 'John')", + "insert into Students (student_id, student_name) values ('6', 'Alex')", + "Truncate table Subjects", + "insert into Subjects (subject_name) values ('Math')", + "insert into Subjects (subject_name) values ('Physics')", + "insert into Subjects (subject_name) values ('Programming')", + "Truncate table Examinations", + "insert into Examinations (student_id, subject_name) values ('1', 'Math')", + "insert into Examinations (student_id, subject_name) values ('1', 'Physics')", + "insert into Examinations (student_id, subject_name) values ('1', 'Programming')", + "insert into Examinations (student_id, subject_name) values ('2', 'Programming')", + "insert into Examinations (student_id, subject_name) values ('1', 'Physics')", + "insert into Examinations (student_id, subject_name) values ('1', 'Math')", + "insert into Examinations (student_id, subject_name) values ('13', 'Math')", + "insert into Examinations (student_id, subject_name) values ('13', 'Programming')", + "insert into Examinations (student_id, subject_name) values ('13', 'Physics')", + "insert into Examinations (student_id, subject_name) values ('2', 'Math')", + "insert into Examinations (student_id, subject_name) values ('1', 'Math')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Students\":[\"student_id\",\"student_name\"],\"Subjects\":[\"subject_name\"],\"Examinations\":[\"student_id\",\"subject_name\"]},\"rows\":{\"Students\":[[1,\"Alice\"],[2,\"Bob\"],[13,\"John\"],[6,\"Alex\"]],\"Subjects\":[[\"Math\"],[\"Physics\"],[\"Programming\"]],\"Examinations\":[[1,\"Math\"],[1,\"Physics\"],[1,\"Programming\"],[2,\"Programming\"],[1,\"Physics\"],[1,\"Math\"],[13,\"Math\"],[13,\"Programming\"],[13,\"Physics\"],[2,\"Math\"],[1,\"Math\"]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/the-number-of-employees-which-report-to-each-employee.json b/leetcode-cn/originData/the-number-of-employees-which-report-to-each-employee.json new file mode 100644 index 00000000..a9381905 --- /dev/null +++ b/leetcode-cn/originData/the-number-of-employees-which-report-to-each-employee.json @@ -0,0 +1,91 @@ +{ + "data": { + "question": { + "questionId": "1882", + "questionFrontendId": "1731", + "categoryTitle": "Database", + "boundTopicId": 572194, + "title": "The Number of Employees Which Report to Each Employee", + "titleSlug": "the-number-of-employees-which-report-to-each-employee", + "content": "

Table: Employees

\n\n
\n+-------------+----------+\n| Column Name | Type     |\n+-------------+----------+\n| employee_id | int      |\n| name        | varchar  |\n| reports_to  | int      |\n| age         | int      |\n+-------------+----------+\nemployee_id is the column with unique values for this table.\nThis table contains information about the employees and the id of the manager they report to. Some employees do not report to anyone (reports_to is null). \n
\n\n

 

\n\n

For this problem, we will consider a manager an employee who has at least 1 other employee reporting to them.

\n\n

Write a solution to report the ids and the names of all managers, the number of employees who report directly to them, and the average age of the reports rounded to the nearest integer.

\n\n

Return the result table ordered by employee_id.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nEmployees table:\n+-------------+---------+------------+-----+\n| employee_id | name    | reports_to | age |\n+-------------+---------+------------+-----+\n| 9           | Hercy   | null       | 43  |\n| 6           | Alice   | 9          | 41  |\n| 4           | Bob     | 9          | 36  |\n| 2           | Winston | null       | 37  |\n+-------------+---------+------------+-----+\nOutput: \n+-------------+-------+---------------+-------------+\n| employee_id | name  | reports_count | average_age |\n+-------------+-------+---------------+-------------+\n| 9           | Hercy | 2             | 39          |\n+-------------+-------+---------------+-------------+\nExplanation: Hercy has 2 people report directly to him, Alice and Bob. Their average age is (41+36)/2 = 38.5, which is 39 after rounding it to the nearest integer.\n
\n", + "translatedTitle": "每位经理的下属员工数量", + "translatedContent": "

Table: Employees

\n\n
+-------------+----------+\n| Column Name | Type     |\n+-------------+----------+\n| employee_id | int      |\n| name        | varchar  |\n| reports_to  | int      |\n| age         | int      |\n+-------------+----------+\nemployee_id 是这个表的主键.\n该表包含员工以及需要听取他们汇报的上级经理的ID的信息。 有些员工不需要向任何人汇报(reports_to 为空)。\n
\n\n

 

\n\n

对于此问题,我们将至少有一个其他员工需要向他汇报的员工,视为一个经理。

\n\n

编写SQL查询需要听取汇报的所有经理的ID、名称、直接向该经理汇报的员工人数,以及这些员工的平均年龄,其中该平均年龄需要四舍五入到最接近的整数。

\n\n

返回的结果集需要按照 employee_id 进行排序。

\n\n

查询结果的格式如下:

\n\n

 

\n\n
Employees table:\n+-------------+---------+------------+-----+\n| employee_id | name    | reports_to | age |\n+-------------+---------+------------+-----+\n| 9           | Hercy   | null       | 43  |\n| 6           | Alice   | 9          | 41  |\n| 4           | Bob     | 9          | 36  |\n| 2           | Winston | null       | 37  |\n+-------------+---------+------------+-----+\n\nResult table:\n+-------------+-------+---------------+-------------+\n| employee_id | name  | reports_count | average_age |\n+-------------+-------+---------------+-------------+\n| 9           | Hercy | 2             | 39          |\n+-------------+-------+---------------+-------------+\nHercy 有两个需要向他汇报的员工, 他们是 Alice and Bob. 他们的平均年龄是 (41+36)/2 = 38.5, 四舍五入的结果是 39.\n
\n", + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 46, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef count_employees(employees: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"19.1K\", \"totalSubmission\": \"41.4K\", \"totalAcceptedRaw\": 19140, \"totalSubmissionRaw\": 41401, \"acRate\": \"46.2%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Employees\":[\"employee_id\",\"name\",\"reports_to\",\"age\"]},\"rows\":{\"Employees\":[[9,\"Hercy\",null,43],[6,\"Alice\",9,41],[4,\"Bob\",9,36],[2,\"Winston\",null,37]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Employees(employee_id int, name varchar(20), reports_to int, age int)\"],\"mssql\":[\"Create table Employees(employee_id int, name varchar(20), reports_to int, age int)\"],\"oraclesql\":[\"Create table Employees(employee_id int, name varchar(20), reports_to int, age int)\"],\"database\":true,\"name\":\"count_employees\",\"pythondata\":[\"Employees = pd.DataFrame([], columns=['employee_id', 'name', 'reports_to', 'age']).astype({'employee_id':'Int64', 'name':'object', 'reports_to':'Int64', 'age':'Int64'})\"],\"postgresql\":[\"Create table If Not Exists Employees(employee_id int, name varchar(20), reports_to int, age int)\"],\"database_schema\":{\"Employees\":{\"employee_id\":\"INT\",\"name\":\"VARCHAR(20)\",\"reports_to\":\"INT\",\"age\":\"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Employees(employee_id int, name varchar(20), reports_to int, age int)", + "Truncate table Employees", + "insert into Employees (employee_id, name, reports_to, age) values ('9', 'Hercy', 'None', '43')", + "insert into Employees (employee_id, name, reports_to, age) values ('6', 'Alice', '9', '41')", + "insert into Employees (employee_id, name, reports_to, age) values ('4', 'Bob', '9', '36')", + "insert into Employees (employee_id, name, reports_to, age) values ('2', 'Winston', 'None', '37')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Employees\":[\"employee_id\",\"name\",\"reports_to\",\"age\"]},\"rows\":{\"Employees\":[[9,\"Hercy\",null,43],[6,\"Alice\",9,41],[4,\"Bob\",9,36],[2,\"Winston\",null,37]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/originData/triangle-judgement.json b/leetcode-cn/originData/triangle-judgement.json new file mode 100644 index 00000000..220ffea0 --- /dev/null +++ b/leetcode-cn/originData/triangle-judgement.json @@ -0,0 +1,89 @@ +{ + "data": { + "question": { + "questionId": "610", + "questionFrontendId": "610", + "categoryTitle": "Database", + "boundTopicId": 2636, + "title": "Triangle Judgement", + "titleSlug": "triangle-judgement", + "content": "

Table: Triangle

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| x           | int  |\n| y           | int  |\n| z           | int  |\n+-------------+------+\nIn SQL, (x, y, z) is the primary key column for this table.\nEach row of this table contains the lengths of three line segments.\n
\n\n

 

\n\n

Report for every three line segments whether they can form a triangle.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nTriangle table:\n+----+----+----+\n| x  | y  | z  |\n+----+----+----+\n| 13 | 15 | 30 |\n| 10 | 20 | 15 |\n+----+----+----+\nOutput: \n+----+----+----+----------+\n| x  | y  | z  | triangle |\n+----+----+----+----------+\n| 13 | 15 | 30 | No       |\n| 10 | 20 | 15 | Yes      |\n+----+----+----+----------+\n
\n", + "translatedTitle": "判断三角形", + "translatedContent": "

表: Triangle

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| x           | int  |\n| y           | int  |\n| z           | int  |\n+-------------+------+\n在 SQL 中,(x, y, z)是该表的主键列。\n该表的每一行包含三个线段的长度。\n
\n\n

 

\n\n

对每三个线段报告它们是否可以形成一个三角形。

\n\n

以 任意顺序 返回结果表。

\n\n

查询结果格式如下所示。

\n\n

 

\n\n

示例 1:

\n\n
\n输入: \nTriangle 表:\n+----+----+----+\n| x  | y  | z  |\n+----+----+----+\n| 13 | 15 | 30 |\n| 10 | 20 | 15 |\n+----+----+----+\n输出: \n+----+----+----+----------+\n| x  | y  | z  | triangle |\n+----+----+----+----------+\n| 13 | 15 | 30 | No       |\n| 10 | 20 | 15 | Yes      |\n+----+----+----+----------+
\n", + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 67, + "dislikes": 0, + "isLiked": null, + "similarQuestions": "[]", + "contributors": [], + "langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}", + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": "数据库", + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef triangle_judgement(triangle: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"36K\", \"totalSubmission\": \"53.7K\", \"totalAcceptedRaw\": 36004, \"totalSubmissionRaw\": 53654, \"acRate\": \"67.1%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Triangle\":[\"x\",\"y\",\"z\"]},\"rows\":{\"Triangle\":[[13,15,30],[10,20,15]]}}", + "metaData": "{\"mysql\":[\"Create table If Not Exists Triangle (x int, y int, z int)\"],\"mssql\":[\"Create table Triangle (x int, y int, z int)\"],\"oraclesql\":[\"Create table Triangle (x int, y int, z int)\"],\"database\":true,\"name\":\"triangle_judgement\",\"pythondata\":[\"Triangle = pd.DataFrame([], columns=['x', 'y', 'z']).astype({'x':'Int64', 'y':'Int64', 'z':'Int64'})\"],\"postgresql\":[\"Create table If Not Exists Triangle (x int, y int, z int)\"],\"database_schema\":{\"Triangle\":{\"x\":\"INT\",\"y\":\"INT\",\"z\":\"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Triangle (x int, y int, z int)", + "Truncate table Triangle", + "insert into Triangle (x, y, z) values ('13', '15', '30')", + "insert into Triangle (x, y, z) values ('10', '20', '15')" + ], + "enableRunCode": true, + "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"

Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"

PostgreSQL 16<\\/p>\"]}", + "book": null, + "isSubscribed": false, + "isDailyQuestion": false, + "dailyRecordStatus": null, + "editorType": "CKEDITOR", + "ugcQuestionId": null, + "style": "LEETCODE", + "exampleTestcases": "{\"headers\":{\"Triangle\":[\"x\",\"y\",\"z\"]},\"rows\":{\"Triangle\":[[13,15,30],[10,20,15]]}}", + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode-cn/problem (Chinese)/2016年的投资 [investments-in-2016].html b/leetcode-cn/problem (Chinese)/2016年的投资 [investments-in-2016].html new file mode 100644 index 00000000..5cea0005 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/2016年的投资 [investments-in-2016].html @@ -0,0 +1,63 @@ +

Insurance 表:

+ +
+
+
++-------------+-------+
+| Column Name | Type  |
++-------------+-------+
+| pid         | int   |
+| tiv_2015    | float |
+| tiv_2016    | float |
+| lat         | float |
+| lon         | float |
++-------------+-------+
+pid 是这张表的主键(具有唯一值的列)。
+表中的每一行都包含一条保险信息,其中:
+pid 是投保人的投保编号。
+tiv_2015 是该投保人在 2015 年的总投保金额,tiv_2016 是该投保人在 2016 年的总投保金额。
+lat 是投保人所在城市的纬度。题目数据确保 lat 不为空。
+lon 是投保人所在城市的经度。题目数据确保 lon 不为空。
+ +

 

+ +

编写解决方案报告 2016 年 (tiv_2016) 所有满足下述条件的投保人的投保金额之和:

+ +
    +
  • 他在 2015 年的投保额 (tiv_2015) 至少跟一个其他投保人在 2015 年的投保额相同。
  • +
  • 他所在的城市必须与其他投保人都不同(也就是说 (lat, lon) 不能跟其他任何一个投保人完全相同)。
  • +
+ +

tiv_2016 四舍五入的 两位小数

+ +

查询结果格式如下例所示。

+ +

 

+ +

示例 1:

+ +
+输入:
+Insurance 表:
++-----+----------+----------+-----+-----+
+| pid | tiv_2015 | tiv_2016 | lat | lon |
++-----+----------+----------+-----+-----+
+| 1   | 10       | 5        | 10  | 10  |
+| 2   | 20       | 20       | 20  | 20  |
+| 3   | 10       | 30       | 20  | 20  |
+| 4   | 10       | 40       | 40  | 40  |
++-----+----------+----------+-----+-----+
+输出:
++----------+
+| tiv_2016 |
++----------+
+| 45.00    |
++----------+
+解释:
+表中的第一条记录和最后一条记录都满足两个条件。
+tiv_2015 值为 10 与第三条和第四条记录相同,且其位置是唯一的。
+
+第二条记录不符合任何一个条件。其 tiv_2015 与其他投保人不同,并且位置与第三条记录相同,这也导致了第三条记录不符合题目要求。
+因此,结果是第一条记录和最后一条记录的 tiv_2016 之和,即 45 。
+
+
diff --git a/leetcode-cn/problem (Chinese)/K 个逆序对数组 [k-inverse-pairs-array].html b/leetcode-cn/problem (Chinese)/K 个逆序对数组 [k-inverse-pairs-array].html new file mode 100644 index 00000000..554b9f15 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/K 个逆序对数组 [k-inverse-pairs-array].html @@ -0,0 +1,32 @@ +

逆序对的定义如下:对于数组 nums 的第 i 个和第 j 个元素,如果满足 0 <= i < j < nums.length 且 nums[i] > nums[j],则其为一个逆序对;否则不是。

+ +

给你两个整数 n 和 k,找出所有包含从 1 到 n 的数字,且恰好拥有 k 个 逆序对 的不同的数组的个数。由于答案可能很大,只需要返回对 109 + 7 取余的结果。

+ +

 

+ +

示例 1:

+ +
+输入:n = 3, k = 0
+输出:1
+解释:
+只有数组 [1,2,3] 包含了从1到3的整数并且正好拥有 0 个逆序对。
+
+ +

示例 2:

+ +
+输入:n = 3, k = 1
+输出:2
+解释:
+数组 [1,3,2] 和 [2,1,3] 都有 1 个逆序对。
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= n <= 1000
  • +
  • 0 <= k <= 1000
  • +
diff --git a/leetcode-cn/problem (Chinese)/上级经理已离职的公司员工 [employees-whose-manager-left-the-company].html b/leetcode-cn/problem (Chinese)/上级经理已离职的公司员工 [employees-whose-manager-left-the-company].html new file mode 100644 index 00000000..0424ca40 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/上级经理已离职的公司员工 [employees-whose-manager-left-the-company].html @@ -0,0 +1,53 @@ +

表: Employees

+ +
++-------------+----------+
+| Column Name | Type     |
++-------------+----------+
+| employee_id | int      |
+| name        | varchar  |
+| manager_id  | int      |
+| salary      | int      |
++-------------+----------+
+在 SQL 中,employee_id 是这个表的主键。
+这个表包含了员工,他们的薪水和上级经理的id。
+有一些员工没有上级经理(其 manager_id 是空值)。
+
+ +

 

+ +

查找这些员工的id,他们的薪水严格少于$30000 并且他们的上级经理已离职。当一个经理离开公司时,他们的信息需要从员工表中删除掉,但是表中的员工的manager_id  这一列还是设置的离职经理的id 。

+ +

返回的结果按照employee_id 从小到大排序。

+ +

查询结果如下所示:

+ +

 

+ +

示例:

+ +
+输入:
+Employees table:
++-------------+-----------+------------+--------+
+| employee_id | name      | manager_id | salary |
++-------------+-----------+------------+--------+
+| 3           | Mila      | 9          | 60301  |
+| 12          | Antonella | null       | 31000  |
+| 13          | Emery     | null       | 67084  |
+| 1           | Kalel     | 11         | 21241  |
+| 9           | Mikaela   | null       | 50937  |
+| 11          | Joziah    | 6          | 28485  |
++-------------+-----------+------------+--------+
+输出:
++-------------+
+| employee_id |
++-------------+
+| 11          |
++-------------+
+
+解释:
+薪水少于 30000 美元的员工有 1 号(Kalel) 和 11号 (Joziah)。
+Kalel 的上级经理是 11 号员工,他还在公司上班(他是 Joziah )。
+Joziah 的上级经理是 6 号员工,他已经离职,因为员工表里面已经没有 6 号员工的信息了,它被删除了。
+
diff --git a/leetcode-cn/problem (Chinese)/两点之间不包含任何点的最宽垂直区域 [widest-vertical-area-between-two-points-containing-no-points].html b/leetcode-cn/problem (Chinese)/两点之间不包含任何点的最宽垂直区域 [widest-vertical-area-between-two-points-containing-no-points].html new file mode 100644 index 00000000..d99c236d --- /dev/null +++ b/leetcode-cn/problem (Chinese)/两点之间不包含任何点的最宽垂直区域 [widest-vertical-area-between-two-points-containing-no-points].html @@ -0,0 +1,33 @@ +

给你 n 个二维平面上的点 points ,其中 points[i] = [xi, yi] ,请你返回两点之间内部不包含任何点的 最宽垂直区域 的宽度。

+ +

垂直区域 的定义是固定宽度,而 y 轴上无限延伸的一块区域(也就是高度为无穷大)。 最宽垂直区域 为宽度最大的一个垂直区域。

+ +

请注意,垂直区域 边上 的点 不在 区域内。

+ +

 

+ +

示例 1:

+​ +
+输入:points = [[8,7],[9,9],[7,4],[9,7]]
+输出:1
+解释:红色区域和蓝色区域都是最优区域。
+
+ +

示例 2:

+ +
+输入:points = [[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]
+输出:3
+
+ +

 

+ +

提示:

+ +
    +
  • n == points.length
  • +
  • 2 <= n <= 105
  • +
  • points[i].length == 2
  • +
  • 0 <= xi, yi <= 109
  • +
diff --git a/leetcode-cn/problem (Chinese)/乘积小于 K 的子数组 [subarray-product-less-than-k].html b/leetcode-cn/problem (Chinese)/乘积小于 K 的子数组 [subarray-product-less-than-k].html new file mode 100644 index 00000000..24ce0db2 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/乘积小于 K 的子数组 [subarray-product-less-than-k].html @@ -0,0 +1,27 @@ +给你一个整数数组 nums 和一个整数 k ,请你返回子数组内所有元素的乘积严格小于 k 的连续子数组的数目。 +

 

+ +

示例 1:

+ +
+输入:nums = [10,5,2,6], k = 100
+输出:8
+解释:8 个乘积小于 100 的子数组分别为:[10]、[5]、[2],、[6]、[10,5]、[5,2]、[2,6]、[5,2,6]。
+需要注意的是 [10,5,2] 并不是乘积小于 100 的子数组。
+
+ +

示例 2:

+ +
+输入:nums = [1,2,3], k = 0
+输出:0
+ +

 

+ +

提示: 

+ +
    +
  • 1 <= nums.length <= 3 * 104
  • +
  • 1 <= nums[i] <= 1000
  • +
  • 0 <= k <= 106
  • +
diff --git a/leetcode-cn/problem (Chinese)/买下所有产品的客户 [customers-who-bought-all-products].html b/leetcode-cn/problem (Chinese)/买下所有产品的客户 [customers-who-bought-all-products].html new file mode 100644 index 00000000..58c53dbd --- /dev/null +++ b/leetcode-cn/problem (Chinese)/买下所有产品的客户 [customers-who-bought-all-products].html @@ -0,0 +1,66 @@ +

Customer 表:

+ +
++-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| customer_id | int     |
+| product_key | int     |
++-------------+---------+
+该表可能包含重复的行。
+customer_id 不为 NULL。
+product_key 是 Product 表的外键(reference 列)。
+
+ +

Product 表:

+ +
++-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| product_key | int     |
++-------------+---------+
+product_key 是这张表的主键(具有唯一值的列)。
+
+ +

 

+ +

编写解决方案,报告 Customer 表中购买了 Product 表中所有产品的客户的 id。

+ +

返回结果表 无顺序要求

+ +

返回结果格式如下所示。

+ +

 

+ +

示例 1:

+ +
+输入:
+Customer 表:
++-------------+-------------+
+| customer_id | product_key |
++-------------+-------------+
+| 1           | 5           |
+| 2           | 6           |
+| 3           | 5           |
+| 3           | 6           |
+| 1           | 6           |
++-------------+-------------+
+Product 表:
++-------------+
+| product_key |
++-------------+
+| 5           |
+| 6           |
++-------------+
+输出:
++-------------+
+| customer_id |
++-------------+
+| 1           |
+| 3           |
++-------------+
+解释:
+购买了所有产品(5 和 6)的客户的 id 是 1 和 3 。
+
diff --git a/leetcode-cn/problem (Chinese)/买卖芯片的最佳时机 [gu-piao-de-zui-da-li-run-lcof].html b/leetcode-cn/problem (Chinese)/买卖芯片的最佳时机 [gu-piao-de-zui-da-li-run-lcof].html new file mode 100644 index 00000000..8fca025b --- /dev/null +++ b/leetcode-cn/problem (Chinese)/买卖芯片的最佳时机 [gu-piao-de-zui-da-li-run-lcof].html @@ -0,0 +1,36 @@ +

数组 prices 记录了某芯片近期的交易价格,其中 prices[i] 表示的 i 天该芯片的价格。你只能选择 某一天 买入芯片,并选择在 未来的某一个不同的日子 卖出该芯片。请设计一个算法计算并返回你从这笔交易中能获取的最大利润。

+ +

如果你不能获取任何利润,返回 0。

+ +

 

+ +

示例 1:

+ +
+输入:prices = [3, 6, 2, 9, 8, 5]
+输出:7
+解释:在第 3 天(芯片价格 = 2)买入,在第 4 天(芯片价格 = 9)卖出,最大利润 = 9 - 2 = 7。
+
+ +

示例 2:

+ +
+输入:prices = [8, 12, 15, 7, 3, 10]
+输出:7
+解释:在第 5 天(芯片价格 = 3)买入,在第 6 天(芯片价格 = 10)卖出,最大利润 = 10 - 3 = 7。
+
+ +

 

+ +

提示:

+ +
    +
  • 0 <= prices.length <= 10^5
  • +
  • 0 <= prices[i] <= 10^4
  • +
+ +

 

+ +

注意:本题与主站 121 题相同:https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/

+ +

 

diff --git a/leetcode-cn/problem (Chinese)/二叉树的序列化与反序列化 [h54YBf].html b/leetcode-cn/problem (Chinese)/二叉树的序列化与反序列化 [h54YBf].html new file mode 100644 index 00000000..e9607232 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/二叉树的序列化与反序列化 [h54YBf].html @@ -0,0 +1,49 @@ +

序列化是将一个数据结构或者对象转换为连续的比特位的操作,进而可以将转换后的数据存储在一个文件或者内存中,同时也可以通过网络传输到另一个计算机环境,采取相反方式重构得到原数据。

+ +

请设计一个算法来实现二叉树的序列化与反序列化。这里不限定你的序列 / 反序列化算法执行逻辑,只需要保证一个二叉树可以被序列化为一个字符串并且将这个字符串反序列化为原始的树结构。

+ +

 

+ +

示例 1:

+ +

+ +
+输入:root = [1,2,3,null,null,4,5]
+输出:[1,2,3,null,null,4,5]
+
+ +

示例 2:

+ +
+输入:root = []
+输出:[]
+
+ +

示例 3:

+ +
+输入:root = [1]
+输出:[1]
+
+ +

示例 4:

+ +
+输入:root = [1,2]
+输出:[1,2]
+
+ +

 

+ +

提示:

+ +
    +
  • 输入输出格式与 LeetCode 目前使用的方式一致,详情请参阅 LeetCode 序列化二叉树的格式。你并非必须采取这种方式,也可以采用其他的方法解决这个问题。
  • +
  • 树中结点数在范围 [0, 104]
  • +
  • -1000 <= Node.val <= 1000
  • +
+ +

 

+ +

注意:本题与主站 297 题相同:https://leetcode-cn.com/problems/serialize-and-deserialize-binary-tree/ 

diff --git a/leetcode-cn/problem (Chinese)/交易逆序对的总数 [shu-zu-zhong-de-ni-xu-dui-lcof].html b/leetcode-cn/problem (Chinese)/交易逆序对的总数 [shu-zu-zhong-de-ni-xu-dui-lcof].html new file mode 100644 index 00000000..99dd9ddb --- /dev/null +++ b/leetcode-cn/problem (Chinese)/交易逆序对的总数 [shu-zu-zhong-de-ni-xu-dui-lcof].html @@ -0,0 +1,17 @@ +

在股票交易中,如果前一天的股价高于后一天的股价,则可以认为存在一个「交易逆序对」。请设计一个程序,输入一段时间内的股票交易记录 record,返回其中存在的「交易逆序对」总数。

+ +

 

+ +

示例 1:

+ +
+输入:record = [9, 7, 5, 4, 6]
+输出:8
+解释:交易中的逆序对为 (9, 7), (9, 5), (9, 4), (9, 6), (7, 5), (7, 4), (7, 6), (5, 4)。
+
+ +

 

+ +

限制:

+ +

0 <= record.length <= 50000

diff --git a/leetcode-cn/problem (Chinese)/产品销售分析 I [product-sales-analysis-i].html b/leetcode-cn/problem (Chinese)/产品销售分析 I [product-sales-analysis-i].html new file mode 100644 index 00000000..540b501c --- /dev/null +++ b/leetcode-cn/problem (Chinese)/产品销售分析 I [product-sales-analysis-i].html @@ -0,0 +1,70 @@ +

销售表 Sales

+ +
++-------------+-------+
+| Column Name | Type  |
++-------------+-------+
+| sale_id     | int   |
+| product_id  | int   |
+| year        | int   |
+| quantity    | int   |
+| price       | int   |
++-------------+-------+
+(sale_id, year) 是销售表 Sales 的主键(具有唯一值的列的组合)。
+product_id 是关联到产品表 Product 的外键(reference 列)。
+该表的每一行显示 product_id 在某一年的销售情况。
+注意: price 表示每单位价格。
+
+ +

产品表 Product

+ +
++--------------+---------+
+| Column Name  | Type    |
++--------------+---------+
+| product_id   | int     |
+| product_name | varchar |
++--------------+---------+
+product_id 是表的主键(具有唯一值的列)。
+该表的每一行表示每种产品的产品名称。
+
+ +

 

+ +

编写解决方案,以获取 Sales 表中所有 sale_id 对应的 product_name 以及该产品的所有 year 和 price

+ +

返回结果表 无顺序要求

+ +

结果格式示例如下。

+ +

 

+ +

示例 1:

+ +
+输入:
+Sales 表:
++---------+------------+------+----------+-------+
+| sale_id | product_id | year | quantity | price |
++---------+------------+------+----------+-------+ 
+| 1       | 100        | 2008 | 10       | 5000  |
+| 2       | 100        | 2009 | 12       | 5000  |
+| 7       | 200        | 2011 | 15       | 9000  |
++---------+------------+------+----------+-------+
+Product 表:
++------------+--------------+
+| product_id | product_name |
++------------+--------------+
+| 100        | Nokia        |
+| 200        | Apple        |
+| 300        | Samsung      |
++------------+--------------+
+输出:
++--------------+-------+-------+
+| product_name | year  | price |
++--------------+-------+-------+
+| Nokia        | 2008  | 5000  |
+| Nokia        | 2009  | 5000  |
+| Apple        | 2011  | 9000  |
++--------------+-------+-------+
+
diff --git a/leetcode-cn/problem (Chinese)/产品销售分析 III [product-sales-analysis-iii].html b/leetcode-cn/problem (Chinese)/产品销售分析 III [product-sales-analysis-iii].html new file mode 100644 index 00000000..5f020715 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/产品销售分析 III [product-sales-analysis-iii].html @@ -0,0 +1,69 @@ +

销售表 Sales

+ +
++-------------+-------+
+| Column Name | Type  |
++-------------+-------+
+| sale_id     | int   |
+| product_id  | int   |
+| year        | int   |
+| quantity    | int   |
+| price       | int   |
++-------------+-------+
+(sale_id, year) 是这张表的主键(具有唯一值的列的组合)。
+product_id 是产品表的外键(reference 列)。
+这张表的每一行都表示:编号 product_id 的产品在某一年的销售额。
+请注意,价格是按每单位计的。
+
+ +

 

+ +

产品表 Product

+ +
++--------------+---------+
+| Column Name  | Type    |
++--------------+---------+
+| product_id   | int     |
+| product_name | varchar |
++--------------+---------+
+product_id 是这张表的主键(具有唯一值的列)。
+这张表的每一行都标识:每个产品的 id 和 产品名称。
+ +

 

+ +

编写解决方案,选出每个售出过的产品 第一年 销售的 产品 id年份数量 价格

+ +

结果表中的条目可以按 任意顺序 排列。

+ +

结果格式如下例所示:

+ +

 

+ +

示例 1:

+ +
+输入:
+Sales 表:
++---------+------------+------+----------+-------+
+| sale_id | product_id | year | quantity | price |
++---------+------------+------+----------+-------+ 
+| 1       | 100        | 2008 | 10       | 5000  |
+| 2       | 100        | 2009 | 12       | 5000  |
+| 7       | 200        | 2011 | 15       | 9000  |
++---------+------------+------+----------+-------+
+Product 表:
++------------+--------------+
+| product_id | product_name |
++------------+--------------+
+| 100        | Nokia        |
+| 200        | Apple        |
+| 300        | Samsung      |
++------------+--------------+
+输出:
++------------+------------+----------+-------+
+| product_id | first_year | quantity | price |
++------------+------------+----------+-------+ 
+| 100        | 2008       | 10       | 5000  |
+| 200        | 2011       | 15       | 9000  |
++------------+------------+----------+-------+
diff --git a/leetcode-cn/problem (Chinese)/从表中创建 DataFrame [create-a-dataframe-from-list].html b/leetcode-cn/problem (Chinese)/从表中创建 DataFrame [create-a-dataframe-from-list].html new file mode 100644 index 00000000..a82fbbe0 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/从表中创建 DataFrame [create-a-dataframe-from-list].html @@ -0,0 +1,31 @@ +

编写一个解决方案,基于名为  student_data 的二维列表 创建 一个 DataFrame 。这个二维列表包含一些学生的 ID 和年龄信息。

+ +

DataFrame 应该有两列, student_id 和 age,并且与原始二维列表的顺序相同。

+ +

返回结果格式如下示例所示。

+ +

 

+ +

示例 1:

+ +
+输入:
+student_data:
+[
+  [1, 15],
+  [2, 11],
+  [3, 11],
+  [4, 20]
+]
+输出:
++------------+-----+
+| student_id | age |
++------------+-----+
+| 1          | 15  |
+| 2          | 11  |
+| 3          | 11  |
+| 4          | 20  |
++------------+-----+
+解释:
+基于 student_data 创建了一个 DataFrame,包含 student_id 和 age 两列。
+
diff --git a/leetcode-cn/problem (Chinese)/使用唯一标识码替换员工ID [replace-employee-id-with-the-unique-identifier].html b/leetcode-cn/problem (Chinese)/使用唯一标识码替换员工ID [replace-employee-id-with-the-unique-identifier].html new file mode 100644 index 00000000..9476894c --- /dev/null +++ b/leetcode-cn/problem (Chinese)/使用唯一标识码替换员工ID [replace-employee-id-with-the-unique-identifier].html @@ -0,0 +1,75 @@ +

Employees 表:

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| id            | int     |
+| name          | varchar |
++---------------+---------+
+在 SQL 中,id 是这张表的主键。
+这张表的每一行分别代表了某公司其中一位员工的名字和 ID 。
+
+ +

 

+ +

EmployeeUNI 表:

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| id            | int     |
+| unique_id     | int     |
++---------------+---------+
+在 SQL 中,(id, unique_id) 是这张表的主键。
+这张表的每一行包含了该公司某位员工的 ID 和他的唯一标识码(unique ID)。
+
+ +

 

+ +

展示每位用户的 唯一标识码(unique ID );如果某位员工没有唯一标识码,使用 null 填充即可。

+ +

你可以以 任意 顺序返回结果表。

+ +

返回结果的格式如下例所示。

+ +

 

+ +

示例 1:

+ +
+输入:
+Employees 表:
++----+----------+
+| id | name     |
++----+----------+
+| 1  | Alice    |
+| 7  | Bob      |
+| 11 | Meir     |
+| 90 | Winston  |
+| 3  | Jonathan |
++----+----------+
+EmployeeUNI 表:
++----+-----------+
+| id | unique_id |
++----+-----------+
+| 3  | 1         |
+| 11 | 2         |
+| 90 | 3         |
++----+-----------+
+输出:
++-----------+----------+
+| unique_id | name     |
++-----------+----------+
+| null      | Alice    |
+| null      | Bob      |
+| 2         | Meir     |
+| 3         | Winston  |
+| 1         | Jonathan |
++-----------+----------+
+解释:
+Alice and Bob 没有唯一标识码, 因此我们使用 null 替代。
+Meir 的唯一标识码是 2 。
+Winston 的唯一标识码是 3 。
+Jonathan 唯一标识码是 1 。
diff --git a/leetcode-cn/problem (Chinese)/修改列 [modify-columns].html b/leetcode-cn/problem (Chinese)/修改列 [modify-columns].html new file mode 100644 index 00000000..5b1db7ac --- /dev/null +++ b/leetcode-cn/problem (Chinese)/修改列 [modify-columns].html @@ -0,0 +1,42 @@ +
+DataFrame employees
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| name        | object |
+| salary      | int    |
++-------------+--------+
+
+ +

一家公司决定增加员工的薪水。

+ +

编写一个解决方案,将每个员工的薪水乘以2来 修改 salary 列。

+ +

返回结果格式如下示例所示。

+ +

 

+ +

示例 1:

+ +
+输入:
+DataFrame employees
++---------+--------+
+| name    | salary |
++---------+--------+
+| Jack    | 19666  |
+| Piper   | 74754  |
+| Mia     | 62509  |
+| Ulysses | 54866  |
++---------+--------+
+输出:
++---------+--------+
+| name    | salary |
++---------+--------+
+| Jack    | 39332  |
+| Piper   | 149508 |
+| Mia     | 125018 |
+| Ulysses | 109732 |
++---------+--------+
+解释:
+每个人的薪水都被加倍。
diff --git a/leetcode-cn/problem (Chinese)/列出指定时间段内所有的下单产品 [list-the-products-ordered-in-a-period].html b/leetcode-cn/problem (Chinese)/列出指定时间段内所有的下单产品 [list-the-products-ordered-in-a-period].html new file mode 100644 index 00000000..c79c4854 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/列出指定时间段内所有的下单产品 [list-the-products-ordered-in-a-period].html @@ -0,0 +1,85 @@ +

表: Products

+ +
++------------------+---------+
+| Column Name      | Type    |
++------------------+---------+
+| product_id       | int     |
+| product_name     | varchar |
+| product_category | varchar |
++------------------+---------+
+product_id 是该表主键(具有唯一值的列)。
+该表包含该公司产品的数据。
+
+ +

 

+ +

表: Orders

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| product_id    | int     |
+| order_date    | date    |
+| unit          | int     |
++---------------+---------+
+该表可能包含重复行。
+product_id 是表单 Products 的外键(reference 列)。
+unit 是在日期 order_date 内下单产品的数目。
+
+ +

 

+ +

写一个解决方案,要求获取在 2020 年 2 月份下单的数量不少于 100 的产品的名字和数目。

+ +

返回结果表单的 顺序无要求

+ +

查询结果的格式如下。

+ +

 

+ +

示例 1:

+ +
+输入:
+Products 表:
++-------------+-----------------------+------------------+
+| product_id  | product_name          | product_category |
++-------------+-----------------------+------------------+
+| 1           | Leetcode Solutions    | Book             |
+| 2           | Jewels of Stringology | Book             |
+| 3           | HP                    | Laptop           |
+| 4           | Lenovo                | Laptop           |
+| 5           | Leetcode Kit          | T-shirt          |
++-------------+-----------------------+------------------+
+Orders 表:
++--------------+--------------+----------+
+| product_id   | order_date   | unit     |
++--------------+--------------+----------+
+| 1            | 2020-02-05   | 60       |
+| 1            | 2020-02-10   | 70       |
+| 2            | 2020-01-18   | 30       |
+| 2            | 2020-02-11   | 80       |
+| 3            | 2020-02-17   | 2        |
+| 3            | 2020-02-24   | 3        |
+| 4            | 2020-03-01   | 20       |
+| 4            | 2020-03-04   | 30       |
+| 4            | 2020-03-04   | 60       |
+| 5            | 2020-02-25   | 50       |
+| 5            | 2020-02-27   | 50       |
+| 5            | 2020-03-01   | 50       |
++--------------+--------------+----------+
+输出:
++--------------------+---------+
+| product_name       | unit    |
++--------------------+---------+
+| Leetcode Solutions | 130     |
+| Leetcode Kit       | 100     |
++--------------------+---------+
+解释:
+2020 年 2 月份下单 product_id = 1 的产品的数目总和为 (60 + 70) = 130 。
+2020 年 2 月份下单 product_id = 2 的产品的数目总和为 80 。
+2020 年 2 月份下单 product_id = 3 的产品的数目总和为 (2 + 3) = 5 。
+2020 年 2 月份 product_id = 4 的产品并没有下单。
+2020 年 2 月份下单 product_id = 5 的产品的数目总和为 (50 + 50) = 100 。
diff --git a/leetcode-cn/problem (Chinese)/创建新列 [create-a-new-column].html b/leetcode-cn/problem (Chinese)/创建新列 [create-a-new-column].html new file mode 100644 index 00000000..2b860f96 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/创建新列 [create-a-new-column].html @@ -0,0 +1,46 @@ +
+DataFrame employees
++-------------+--------+
+| Column Name | Type.  |
++-------------+--------+
+| name        | object |
+| salary      | int.   |
++-------------+--------+
+
+ +

一家公司计划为员工提供奖金。

+ +

编写一个解决方案,创建一个名为 bonus 的新列,其中包含 salary 值的 两倍

+ +

返回结果格式如下示例所示。

+ +

 

+ +

示例 1:

+ +
+输入:
+DataFrame employees
++---------+--------+
+| name    | salary |
++---------+--------+
+| Piper   | 4548   |
+| Grace   | 28150  |
+| Georgia | 1103   |
+| Willow  | 6593   |
+| Finn    | 74576  |
+| Thomas  | 24433  |
++---------+--------+
+输出:
++---------+--------+--------+
+| name    | salary | bonus  |
++---------+--------+--------+
+| Piper   | 4548   | 9096   |
+| Grace   | 28150  | 56300  |
+| Georgia | 1103   | 2206   |
+| Willow  |  593   | 13186  |
+| Finn    | 74576  | 149152 |
+| Thomas  | 24433  | 48866  |
++---------+--------+--------+
+解释:
+通过将 salary 列中的值加倍创建了一个新的 bonus 列。
diff --git a/leetcode-cn/problem (Chinese)/删去丢失的数据 [drop-missing-data].html b/leetcode-cn/problem (Chinese)/删去丢失的数据 [drop-missing-data].html new file mode 100644 index 00000000..7ec6b85a --- /dev/null +++ b/leetcode-cn/problem (Chinese)/删去丢失的数据 [drop-missing-data].html @@ -0,0 +1,41 @@ +
+DataFrame students
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| student_id  | int    |
+| name        | object |
+| age         | int    |
++-------------+--------+
+
+ +

name 列里有一些具有缺失值的行。

+ +

编写一个解决方案,删除具有缺失值的行。

+ +

返回结果格式如下示例所示。

+ +

 

+ +

示例 1:

+ +
+输入:
++------------+---------+-----+
+| student_id | name    | age |
++------------+---------+-----+
+| 32         | Piper   | 5   |
+| 217        | None    | 19  |
+| 779        | Georgia | 20  |
+| 849        | Willow  | 14  |
++------------+---------+-----+
+输出:
++------------+---------+-----+
+| student_id | name    | age |
++------------+---------+-----+
+| 32         | Piper   | 5   |
+| 779        | Georgia | 20  | 
+| 849        | Willow  | 14  | 
++------------+---------+-----+
+解释:
+学号为 217 的学生所在行在 name 列中有空值,因此这一行将被删除。
diff --git a/leetcode-cn/problem (Chinese)/删去重复的行 [drop-duplicate-rows].html b/leetcode-cn/problem (Chinese)/删去重复的行 [drop-duplicate-rows].html new file mode 100644 index 00000000..277d6b0f --- /dev/null +++ b/leetcode-cn/problem (Chinese)/删去重复的行 [drop-duplicate-rows].html @@ -0,0 +1,46 @@ +
+DataFrame customers
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| customer_id | int    |
+| name        | object |
+| email       | object |
++-------------+--------+
+
+ +

在 DataFrame 中基于 email 列存在一些重复行。

+ +

编写一个解决方案,删除这些重复行,仅保留第一次出现的行。

+ +

返回结果格式如下例所示。

+ +

 

+ +

示例 1:

+ +
+输入:
++-------------+---------+---------------------+
+| customer_id | name    | email               |
++-------------+---------+---------------------+
+| 1           | Ella    | emily@example.com   |
+| 2           | David   | michael@example.com |
+| 3           | Zachary | sarah@example.com   |
+| 4           | Alice   | john@example.com    |
+| 5           | Finn    | john@example.com    |
+| 6           | Violet  | alice@example.com   |
++-------------+---------+---------------------+
+输出:
++-------------+---------+---------------------+
+| customer_id | name    | email               |
++-------------+---------+---------------------+
+| 1           | Ella    | emily@example.com   |
+| 2           | David   | michael@example.com |
+| 3           | Zachary | sarah@example.com   |
+| 4           | Alice   | john@example.com    |
+| 6           | Violet  | alice@example.com   |
++-------------+---------+---------------------+
+解释:
+Alice (customer_id = 4) 和 Finn (customer_id = 5) 都使用 john@example.com,因此只保留该邮箱地址的第一次出现。
+
diff --git a/leetcode-cn/problem (Chinese)/判断三角形 [triangle-judgement].html b/leetcode-cn/problem (Chinese)/判断三角形 [triangle-judgement].html new file mode 100644 index 00000000..9319a339 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/判断三角形 [triangle-judgement].html @@ -0,0 +1,42 @@ +

表: Triangle

+ +
++-------------+------+
+| Column Name | Type |
++-------------+------+
+| x           | int  |
+| y           | int  |
+| z           | int  |
++-------------+------+
+在 SQL 中,(x, y, z)是该表的主键列。
+该表的每一行包含三个线段的长度。
+
+ +

 

+ +

对每三个线段报告它们是否可以形成一个三角形。

+ +

以 任意顺序 返回结果表。

+ +

查询结果格式如下所示。

+ +

 

+ +

示例 1:

+ +
+输入: 
+Triangle 表:
++----+----+----+
+| x  | y  | z  |
++----+----+----+
+| 13 | 15 | 30 |
+| 10 | 20 | 15 |
++----+----+----+
+输出: 
++----+----+----+----------+
+| x  | y  | z  | triangle |
++----+----+----+----------+
+| 13 | 15 | 30 | No       |
+| 10 | 20 | 15 | Yes      |
++----+----+----+----------+
diff --git a/leetcode-cn/problem (Chinese)/判断对称二叉树 [dui-cheng-de-er-cha-shu-lcof].html b/leetcode-cn/problem (Chinese)/判断对称二叉树 [dui-cheng-de-er-cha-shu-lcof].html new file mode 100644 index 00000000..c91fd570 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/判断对称二叉树 [dui-cheng-de-er-cha-shu-lcof].html @@ -0,0 +1,31 @@ +

请设计一个函数判断一棵二叉树是否 轴对称

+ +

 

+ +

示例 1:

+ +

+ +
+输入:root = [6,7,7,8,9,9,8]
+输出:true
+解释:从图中可看出树是轴对称的。
+ +

示例 2:

+ +

+ +
+输入:root = [1,2,2,null,3,null,3]
+输出:false
+解释:从图中可看出最后一层的节点不对称。
+ +

 

+ +

提示:

+ +

0 <= 节点个数 <= 1000

+ +

注意:本题与主站 101 题相同:https://leetcode-cn.com/problems/symmetric-tree/

+ +

 

diff --git a/leetcode-cn/problem (Chinese)/判断是否为平衡二叉树 [ping-heng-er-cha-shu-lcof].html b/leetcode-cn/problem (Chinese)/判断是否为平衡二叉树 [ping-heng-er-cha-shu-lcof].html new file mode 100644 index 00000000..5f0a4b57 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/判断是否为平衡二叉树 [ping-heng-er-cha-shu-lcof].html @@ -0,0 +1,31 @@ +

输入一棵二叉树的根节点,判断该树是不是平衡二叉树。如果某二叉树中任意节点的左右子树的深度相差不超过1,那么它就是一棵平衡二叉树。

+ +

 

+ +

示例 1:

+ +
+输入:root = [3,9,20,null,null,15,7]
+输出:true 
+解释:如下图
+
+ +


+
+示例 2:

+ +
+输入:root = [1,2,2,3,3,null,null,4,4]
+输出:false
+解释:如下图
+
+ +

 

+ +

提示:

+ +
    +
  • 0 <= 树的结点个数 <= 10000
  • +
+ +

注意:本题与主站 110 题相同:https://leetcode-cn.com/problems/balanced-binary-tree/

diff --git a/leetcode-cn/problem (Chinese)/加密运算 [bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof].html b/leetcode-cn/problem (Chinese)/加密运算 [bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof].html new file mode 100644 index 00000000..a73ccf5d --- /dev/null +++ b/leetcode-cn/problem (Chinese)/加密运算 [bu-yong-jia-jian-cheng-chu-zuo-jia-fa-lcof].html @@ -0,0 +1,29 @@ +

计算机安全专家正在开发一款高度安全的加密通信软件,需要在进行数据传输时对数据进行加密和解密操作。假定 dataAdataB 分别为随机抽样的两次通信的数据量:

+ +
    +
  • 正数为发送量
  • +
  • 负数为接受量
  • +
  • 0 为数据遗失
  • +
+ +

请不使用四则运算符的情况下实现一个函数计算两次通信的数据量之和(三种情况均需被统计),以确保在数据传输过程中的高安全性和保密性。

+ +

 

+ +

示例 1:

+ +
+输入:dataA = 5, dataB = -1
+输出:4
+
+ +

 

+ +

提示:

+ +
    +
  • dataA 和 dataB 均可能是负数或 0
  • +
  • 结果不会溢出 32 位整数
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/动态口令 [zuo-xuan-zhuan-zi-fu-chuan-lcof].html b/leetcode-cn/problem (Chinese)/动态口令 [zuo-xuan-zhuan-zi-fu-chuan-lcof].html new file mode 100644 index 00000000..34b81d5a --- /dev/null +++ b/leetcode-cn/problem (Chinese)/动态口令 [zuo-xuan-zhuan-zi-fu-chuan-lcof].html @@ -0,0 +1,34 @@ +

某公司门禁密码使用动态口令技术。初始密码为字符串 password,密码更新均遵循以下步骤:

+ +
    +
  • 设定一个正整数目标值 target
  • +
  • passwordtarget 个字符按原顺序移动至字符串末尾
  • +
+ +

请返回更新后的密码字符串。

+ +

 

+ +

示例 1:

+ +
+输入: password = "s3cur1tyC0d3", target = 4
+输出: "r1tyC0d3s3cu"
+
+ +

示例 2:

+ +
+输入: password = "lrloseumgh", target = 6
+输出: "umghlrlose"
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= target < password.length <= 10000
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/即时食物配送 II [immediate-food-delivery-ii].html b/leetcode-cn/problem (Chinese)/即时食物配送 II [immediate-food-delivery-ii].html new file mode 100644 index 00000000..a1afabcd --- /dev/null +++ b/leetcode-cn/problem (Chinese)/即时食物配送 II [immediate-food-delivery-ii].html @@ -0,0 +1,56 @@ +

配送表: Delivery

+ +
++-----------------------------+---------+
+| Column Name                 | Type    |
++-----------------------------+---------+
+| delivery_id                 | int     |
+| customer_id                 | int     |
+| order_date                  | date    |
+| customer_pref_delivery_date | date    |
++-----------------------------+---------+
+delivery_id 是该表中具有唯一值的列。
+该表保存着顾客的食物配送信息,顾客在某个日期下了订单,并指定了一个期望的配送日期(和下单日期相同或者在那之后)。
+
+ +

 

+ +

如果顾客期望的配送日期和下单日期相同,则该订单称为 「即时订单」,否则称为「计划订单」。

+ +

首次订单」是顾客最早创建的订单。我们保证一个顾客只会有一个「首次订单」。

+ +

编写解决方案以获取即时订单在所有用户的首次订单中的比例。保留两位小数。

+ +

结果示例如下所示:

+ +

 

+ +

示例 1:

+ +
+输入:
+Delivery 表:
++-------------+-------------+------------+-----------------------------+
+| delivery_id | customer_id | order_date | customer_pref_delivery_date |
++-------------+-------------+------------+-----------------------------+
+| 1           | 1           | 2019-08-01 | 2019-08-02                  |
+| 2           | 2           | 2019-08-02 | 2019-08-02                  |
+| 3           | 1           | 2019-08-11 | 2019-08-12                  |
+| 4           | 3           | 2019-08-24 | 2019-08-24                  |
+| 5           | 3           | 2019-08-21 | 2019-08-22                  |
+| 6           | 2           | 2019-08-11 | 2019-08-13                  |
+| 7           | 4           | 2019-08-09 | 2019-08-09                  |
++-------------+-------------+------------+-----------------------------+
+输出:
++----------------------+
+| immediate_percentage |
++----------------------+
+| 50.00                |
++----------------------+
+解释:
+1 号顾客的 1 号订单是首次订单,并且是计划订单。
+2 号顾客的 2 号订单是首次订单,并且是即时订单。
+3 号顾客的 5 号订单是首次订单,并且是计划订单。
+4 号顾客的 7 号订单是首次订单,并且是即时订单。
+因此,一半顾客的首次订单是即时的。
+
diff --git a/leetcode-cn/problem (Chinese)/只出现一次的最大数字 [biggest-single-number].html b/leetcode-cn/problem (Chinese)/只出现一次的最大数字 [biggest-single-number].html new file mode 100644 index 00000000..1c571578 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/只出现一次的最大数字 [biggest-single-number].html @@ -0,0 +1,80 @@ +

MyNumbers 表:

+ +
+
+
++-------------+------+
+| Column Name | Type |
++-------------+------+
+| num         | int  |
++-------------+------+
+该表可能包含重复项(换句话说,在SQL中,该表没有主键)。
+这张表的每一行都含有一个整数。
+
+ +

 

+ +

单一数字 是在 MyNumbers 表中只出现一次的数字。

+ +

找出最大的 单一数字 。如果不存在 单一数字 ,则返回 null

+ +

查询结果如下例所示。

+ + +

 

+ +

示例 1:

+ +
+输入:
+MyNumbers 表:
++-----+
+| num |
++-----+
+| 8   |
+| 8   |
+| 3   |
+| 3   |
+| 1   |
+| 4   |
+| 5   |
+| 6   |
++-----+
+输出:
++-----+
+| num |
++-----+
+| 6   |
++-----+
+解释:单一数字有 1、4、5 和 6 。
+6 是最大的单一数字,返回 6 。
+
+ +

示例 2:

+ +
+输入:
+MyNumbers table:
++-----+
+| num |
++-----+
+| 8   |
+| 8   |
+| 7   |
+| 7   |
+| 3   |
+| 3   |
+| 3   |
++-----+
+输出:
++------+
+| num  |
++------+
+| null |
++------+
+解释:输入的表中不存在单一数字,所以返回 null 。
+
+
+
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/各赛事的用户注册率 [percentage-of-users-attended-a-contest].html b/leetcode-cn/problem (Chinese)/各赛事的用户注册率 [percentage-of-users-attended-a-contest].html new file mode 100644 index 00000000..4eddb62f --- /dev/null +++ b/leetcode-cn/problem (Chinese)/各赛事的用户注册率 [percentage-of-users-attended-a-contest].html @@ -0,0 +1,80 @@ +

用户表: Users

+ +
++-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| user_id     | int     |
+| user_name   | varchar |
++-------------+---------+
+user_id 是该表的主键(具有唯一值的列)。
+该表中的每行包括用户 ID 和用户名。
+ +

 

+ +

注册表: Register

+ +
++-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| contest_id  | int     |
+| user_id     | int     |
++-------------+---------+
+(contest_id, user_id) 是该表的主键(具有唯一值的列的组合)。
+该表中的每行包含用户的 ID 和他们注册的赛事。
+ +

 

+ +

编写解决方案统计出各赛事的用户注册百分率,保留两位小数。

+ +

返回的结果表按 percentage 的 降序 排序,若相同则按 contest_id 的 升序 排序。

+ +

返回结果如下示例所示。

+ +

 

+ +

示例 1:

+ +
+输入:
+Users 表:
++---------+-----------+
+| user_id | user_name |
++---------+-----------+
+| 6       | Alice     |
+| 2       | Bob       |
+| 7       | Alex      |
++---------+-----------+
+
+Register 表:
++------------+---------+
+| contest_id | user_id |
++------------+---------+
+| 215        | 6       |
+| 209        | 2       |
+| 208        | 2       |
+| 210        | 6       |
+| 208        | 6       |
+| 209        | 7       |
+| 209        | 6       |
+| 215        | 7       |
+| 208        | 7       |
+| 210        | 2       |
+| 207        | 2       |
+| 210        | 7       |
++------------+---------+
+输出:
++------------+------------+
+| contest_id | percentage |
++------------+------------+
+| 208        | 100.0      |
+| 209        | 100.0      |
+| 210        | 100.0      |
+| 215        | 66.67      |
+| 207        | 33.33      |
++------------+------------+
+解释:
+所有用户都注册了 208、209 和 210 赛事,因此这些赛事的注册率为 100% ,我们按 contest_id 的降序排序加入结果表中。
+Alice 和 Alex 注册了 215 赛事,注册率为 ((2/3) * 100) = 66.67%
+Bob 注册了 207 赛事,注册率为 ((1/3) * 100) = 33.33%
diff --git a/leetcode-cn/problem (Chinese)/员工奖金 [employee-bonus].html b/leetcode-cn/problem (Chinese)/员工奖金 [employee-bonus].html new file mode 100644 index 00000000..950d0cae --- /dev/null +++ b/leetcode-cn/problem (Chinese)/员工奖金 [employee-bonus].html @@ -0,0 +1,69 @@ +

表:Employee 

+ +
++-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| empId       | int     |
+| name        | varchar |
+| supervisor  | int     |
+| salary      | int     |
++-------------+---------+
+empId 是该表中具有唯一值的列。
+该表的每一行都表示员工的姓名和 id,以及他们的工资和经理的 id。
+
+ +

 

+ +

表:Bonus

+ +
++-------------+------+
+| Column Name | Type |
++-------------+------+
+| empId       | int  |
+| bonus       | int  |
++-------------+------+
+empId 是该表具有唯一值的列。
+empId 是 Employee 表中 empId 的外键(reference 列)。
+该表的每一行都包含一个员工的 id 和他们各自的奖金。
+
+ +

 

+ +

编写解决方案,报告每个奖金 少于 1000 的员工的姓名和奖金数额。

+ +

任意顺序 返回结果表。

+ +

结果格式如下所示。

+ +

 

+ +

示例 1:

+ +
+输入:
+Employee table:
++-------+--------+------------+--------+
+| empId | name   | supervisor | salary |
++-------+--------+------------+--------+
+| 3     | Brad   | null       | 4000   |
+| 1     | John   | 3          | 1000   |
+| 2     | Dan    | 3          | 2000   |
+| 4     | Thomas | 3          | 4000   |
++-------+--------+------------+--------+
+Bonus table:
++-------+-------+
+| empId | bonus |
++-------+-------+
+| 2     | 500   |
+| 4     | 2000  |
++-------+-------+
+输出:
++------+-------+
+| name | bonus |
++------+-------+
+| Brad | null  |
+| John | null  |
+| Dan  | 500   |
++------+-------+
diff --git a/leetcode-cn/problem (Chinese)/员工的直属部门 [primary-department-for-each-employee].html b/leetcode-cn/problem (Chinese)/员工的直属部门 [primary-department-for-each-employee].html new file mode 100644 index 00000000..b4f141d9 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/员工的直属部门 [primary-department-for-each-employee].html @@ -0,0 +1,60 @@ +

表:Employee

+ +
++---------------+---------+
+| Column Name   |  Type   |
++---------------+---------+
+| employee_id   | int     |
+| department_id | int     |
+| primary_flag  | varchar |
++---------------+---------+
+这张表的主键为 employee_id, department_id (具有唯一值的列的组合)
+employee_id 是员工的ID
+department_id 是部门的ID,表示员工与该部门有关系
+primary_flag 是一个枚举类型,值分别为('Y', 'N'). 如果值为'Y',表示该部门是员工的直属部门。 如果值是'N',则否
+
+ +

 

+ +

一个员工可以属于多个部门。当一个员工加入超过一个部门的时候,他需要决定哪个部门是他的直属部门。请注意,当员工只加入一个部门的时候,那这个部门将默认为他的直属部门,虽然表记录的值为'N'.

+ +

请编写解决方案,查出员工所属的直属部门。

+ +

返回结果 没有顺序要求

+ +

返回结果格式如下例子所示:

+ +

 

+ +

示例 1:

+ +
+输入:
+Employee table:
++-------------+---------------+--------------+
+| employee_id | department_id | primary_flag |
++-------------+---------------+--------------+
+| 1           | 1             | N            |
+| 2           | 1             | Y            |
+| 2           | 2             | N            |
+| 3           | 3             | N            |
+| 4           | 2             | N            |
+| 4           | 3             | Y            |
+| 4           | 4             | N            |
++-------------+---------------+--------------+
+输出:
++-------------+---------------+
+| employee_id | department_id |
++-------------+---------------+
+| 1           | 1             |
+| 2           | 1             |
+| 3           | 3             |
+| 4           | 3             |
++-------------+---------------+
+解释:
+- 员工 1 的直属部门是 1
+- 员工 2 的直属部门是 1
+- 员工 3 的直属部门是 3
+- 员工 4 的直属部门是 3
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/图书整理 I [cong-wei-dao-tou-da-yin-lian-biao-lcof].html b/leetcode-cn/problem (Chinese)/图书整理 I [cong-wei-dao-tou-da-yin-lian-biao-lcof].html new file mode 100644 index 00000000..95bdef69 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/图书整理 I [cong-wei-dao-tou-da-yin-lian-biao-lcof].html @@ -0,0 +1,17 @@ +

书店店员有一张链表形式的书单,每个节点代表一本书,节点中的值表示书的编号。为更方便整理书架,店员需要将书单倒过来排列,就可以从最后一本书开始整理,逐一将书放回到书架上。请倒序返回这个书单链表。

+ +

 

+ +

示例 1:

+ +
+输入:head = [3,6,4,1]
+
+输出:[1,4,6,3]
+
+ +

 

+ +

提示:

+ +

0 <= 链表长度 <= 10000

diff --git a/leetcode-cn/problem (Chinese)/图书整理 II [yong-liang-ge-zhan-shi-xian-dui-lie-lcof].html b/leetcode-cn/problem (Chinese)/图书整理 II [yong-liang-ge-zhan-shi-xian-dui-lie-lcof].html new file mode 100644 index 00000000..9e2e3509 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/图书整理 II [yong-liang-ge-zhan-shi-xian-dui-lie-lcof].html @@ -0,0 +1,36 @@ +

读者来到图书馆排队借还书,图书管理员使用两个书车来完成整理借还书的任务。书车中的书从下往上叠加存放,图书管理员每次只能拿取书车顶部的书。排队的读者会有两种操作:

+ +
    +
  • push(bookID):把借阅的书籍还到图书馆。
  • +
  • pop():从图书馆中借出书籍。
  • +
+ +

为了保持图书的顺序,图书管理员每次取出供读者借阅的书籍是 最早 归还到图书馆的书籍。你需要返回 每次读者借出书的值

+ +

如果没有归还的书可以取出,返回 -1

+ +

 

+ +

示例 1:

+ +
+输入:
+["BookQueue", "push", "push", "pop"]
+[[], [1], [2], []]
+输出:[null,null,null,1]
+解释:
+MyQueue myQueue = new MyQueue();
+myQueue.push(1); // queue is: [1]
+myQueue.push(2); // queue is: [1, 2] (leftmost is front of the queue)
+myQueue.pop(); // return 1, queue is [2]
+ +

 

+ +

提示:

+ +
    +
  • 1 <= bookID <= 10000
  • +
  • 最多会对 pushpop 进行 10000 次调用
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/填充缺失值 [fill-missing-data].html b/leetcode-cn/problem (Chinese)/填充缺失值 [fill-missing-data].html new file mode 100644 index 00000000..c637ba68 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/填充缺失值 [fill-missing-data].html @@ -0,0 +1,39 @@ +
+DataFrame products
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| name        | object |
+| quantity    | int    |
+| price       | int    |
++-------------+--------+
+
+ +

编写一个解决方案,在 quantity 列中将缺失的值填充为 0

+ +

返回结果如下示例所示。

+ +

 

+示例 1: + +
+输入:
++-----------------+----------+-------+
+| name            | quantity | price |
++-----------------+----------+-------+
+| Wristwatch      | 32       | 135   |
+| WirelessEarbuds | None     | 821   |
+| GolfClubs       | None     | 9319  |
+| Printer         | 849      | 3051  |
++-----------------+----------+-------+
+输出:
++-----------------+----------+-------+
+| name            | quantity | price |
++-----------------+----------+-------+
+| Wristwatch      | 32       | 135   |
+| WirelessEarbuds | 0        | 821   |
+| GolfClubs       | 0        | 9319  |
+| Printer         | 849      | 3051  |
++-----------------+----------+-------+
+解释:
+Toaster 和 Headphones 的数量被填充为 0。
diff --git a/leetcode-cn/problem (Chinese)/套餐内商品的排列顺序 [zi-fu-chuan-de-pai-lie-lcof].html b/leetcode-cn/problem (Chinese)/套餐内商品的排列顺序 [zi-fu-chuan-de-pai-lie-lcof].html new file mode 100644 index 00000000..c7f9e6cf --- /dev/null +++ b/leetcode-cn/problem (Chinese)/套餐内商品的排列顺序 [zi-fu-chuan-de-pai-lie-lcof].html @@ -0,0 +1,22 @@ +

某店铺将用于组成套餐的商品记作字符串 goods,其中 goods[i] 表示对应商品。请返回该套餐内所含商品的 全部排列方式

+ +

返回结果 无顺序要求,但不能含有重复的元素。

+ +

 

+ +

示例 1:

+ +
+输入:goods = "agew"
+输出:["aegw","aewg","agew","agwe","aweg","awge","eagw","eawg","egaw","egwa","ewag","ewga","gaew","gawe","geaw","gewa","gwae","gwea","waeg","wage","weag","wega","wgae","wgea"]
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= goods.length <= 8
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/好友申请 II :谁有最多的好友 [friend-requests-ii-who-has-the-most-friends].html b/leetcode-cn/problem (Chinese)/好友申请 II :谁有最多的好友 [friend-requests-ii-who-has-the-most-friends].html new file mode 100644 index 00000000..90ff8333 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/好友申请 II :谁有最多的好友 [friend-requests-ii-who-has-the-most-friends].html @@ -0,0 +1,53 @@ +

RequestAccepted 表:

+ +
+
+
++----------------+---------+
+| Column Name    | Type    |
++----------------+---------+
+| requester_id   | int     |
+| accepter_id    | int     |
+| accept_date    | date    |
++----------------+---------+
+(requester_id, accepter_id) 是这张表的主键(具有唯一值的列的组合)。
+这张表包含发送好友请求的人的 ID ,接收好友请求的人的 ID ,以及好友请求通过的日期。
+
+ +

 

+ +

编写解决方案,找出拥有最多的好友的人和他拥有的好友数目。

+ +

生成的测试用例保证拥有最多好友数目的只有 1 个人。

+ +

查询结果格式如下例所示。

+ +

 

+ +

示例 1:

+ +
+输入:
+RequestAccepted 表:
++--------------+-------------+-------------+
+| requester_id | accepter_id | accept_date |
++--------------+-------------+-------------+
+| 1            | 2           | 2016/06/03  |
+| 1            | 3           | 2016/06/08  |
+| 2            | 3           | 2016/06/08  |
+| 3            | 4           | 2016/06/09  |
++--------------+-------------+-------------+
+输出:
++----+-----+
+| id | num |
++----+-----+
+| 3  | 3   |
++----+-----+
+解释:
+编号为 3 的人是编号为 1 ,2 和 4 的人的好友,所以他总共有 3 个好友,比其他人都多。
+ +

 

+ +

进阶:在真实世界里,可能会有多个人拥有好友数相同且最多,你能找到所有这些人吗?

+
+
diff --git a/leetcode-cn/problem (Chinese)/子结构判断 [shu-de-zi-jie-gou-lcof].html b/leetcode-cn/problem (Chinese)/子结构判断 [shu-de-zi-jie-gou-lcof].html new file mode 100644 index 00000000..ee36adf7 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/子结构判断 [shu-de-zi-jie-gou-lcof].html @@ -0,0 +1,33 @@ +

给定两棵二叉树 tree1tree2,判断 tree2 是否以 tree1 的某个节点为根的子树具有 相同的结构和节点值
+注意,空树 不会是以 tree1 的某个节点为根的子树具有 相同的结构和节点值

+ +

 

+ +

示例 1:

+ +

 

+ +

+ +

 

+ +
+输入:tree1 = [1,7,5], tree2 = [6,1]
+输出:false
+解释:tree2 与 tree1 的一个子树没有相同的结构和节点值。
+
+ +

示例 2:

+ +

+ +
+输入:tree1 = [3,6,7,1,8], tree2 = [6,1]
+输出:true
+解释:tree2 与 tree1 的一个子树拥有相同的结构和节点值。即 6 - > 1。
+ +

 

+ +

提示:

+ +

0 <= 节点个数 <= 10000

diff --git a/leetcode-cn/problem (Chinese)/字母迷宫 [ju-zhen-zhong-de-lu-jing-lcof].html b/leetcode-cn/problem (Chinese)/字母迷宫 [ju-zhen-zhong-de-lu-jing-lcof].html new file mode 100644 index 00000000..58db1679 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/字母迷宫 [ju-zhen-zhong-de-lu-jing-lcof].html @@ -0,0 +1,49 @@ +

字母迷宫游戏初始界面记作 m x n 二维字符串数组 grid,请判断玩家是否能在 grid 中找到目标单词 target
+注意:寻找单词时 必须 按照字母顺序,通过水平或垂直方向相邻的单元格内的字母构成,同时,同一个单元格内的字母 不允许被重复使用 

+ +

 

+ +

+ +

 

+ +

示例 1:

+ +
+输入:grid = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], target = "ABCCED"
+输出:true
+
+ +

示例 2:

+ +
+输入:grid = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], target = "SEE"
+输出:true
+
+ +

示例 3:

+ +
+输入:grid = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], target = "ABCB"
+输出:false
+
+ +

 

+ +

提示:

+ +
    +
  • m == grid.length
  • +
  • n = grid[i].length
  • +
  • 1 <= m, n <= 6
  • +
  • 1 <= target.length <= 15
  • +
  • gridtarget 仅由大小写英文字母组成
  • +
+ +

 

+ +

注意:本题与主站 79 题相同:https://leetcode-cn.com/problems/word-search/

+ +

 

+ +

 

diff --git a/leetcode-cn/problem (Chinese)/字符串中的单词反转 [fan-zhuan-dan-ci-shun-xu-lcof].html b/leetcode-cn/problem (Chinese)/字符串中的单词反转 [fan-zhuan-dan-ci-shun-xu-lcof].html new file mode 100644 index 00000000..2ebef570 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/字符串中的单词反转 [fan-zhuan-dan-ci-shun-xu-lcof].html @@ -0,0 +1,47 @@ +

你在与一位习惯从右往左阅读的朋友发消息,他发出的文字顺序都与正常相反但单词内容正确,为了和他顺利交流你决定写一个转换程序,把他所发的消息 message 转换为正常语序。

+ +

注意:输入字符串 message 中可能会存在前导空格、尾随空格或者单词间的多个空格。返回的结果字符串中,单词间应当仅用单个空格分隔,且不包含任何额外的空格。

+ +

 

+ +

示例 1:

+ +
+输入: message = "the sky is blue"
+输出: "blue is sky the"
+
+ +

示例 2:

+ +
+输入: message = "  hello world!  "
+输出: "world! hello"
+解释: 输入字符串可以在前面或者后面包含多余的空格,但是反转后的字符不能包括。
+
+ +

示例 3:

+ +
+输入: message = "a good   example"
+输出: "example good a"
+解释: 如果两个单词间有多余的空格,将反转后单词间的空格减少到只含一个。
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= message.length <= 10^4
  • +
  • message 中包含英文大小写字母、空格和数字
  • +
  • message 中至少有一个单词
  • +
  •  
  • +
+ +

注意:

+ + + +

 

diff --git a/leetcode-cn/problem (Chinese)/学生们参加各科测试的次数 [students-and-examinations].html b/leetcode-cn/problem (Chinese)/学生们参加各科测试的次数 [students-and-examinations].html new file mode 100644 index 00000000..3faf6d74 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/学生们参加各科测试的次数 [students-and-examinations].html @@ -0,0 +1,112 @@ +

学生表: Students

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| student_id    | int     |
+| student_name  | varchar |
++---------------+---------+
+在 SQL 中,主键为 student_id(学生ID)。
+该表内的每一行都记录有学校一名学生的信息。
+
+ +

 

+ +

科目表: Subjects

+ +
++--------------+---------+
+| Column Name  | Type    |
++--------------+---------+
+| subject_name | varchar |
++--------------+---------+
+在 SQL 中,主键为 subject_name(科目名称)。
+每一行记录学校的一门科目名称。
+
+ +

 

+ +

考试表: Examinations

+ +
++--------------+---------+
+| Column Name  | Type    |
++--------------+---------+
+| student_id   | int     |
+| subject_name | varchar |
++--------------+---------+
+这个表可能包含重复数据(换句话说,在 SQL 中,这个表没有主键)。
+学生表里的一个学生修读科目表里的每一门科目。
+这张考试表的每一行记录就表示学生表里的某个学生参加了一次科目表里某门科目的测试。
+
+ +

 

+ +

查询出每个学生参加每一门科目测试的次数,结果按 student_idsubject_name 排序。

+ +

查询结构格式如下所示。

+ +

 

+ +

示例 1:

+ +
+输入:
+Students table:
++------------+--------------+
+| student_id | student_name |
++------------+--------------+
+| 1          | Alice        |
+| 2          | Bob          |
+| 13         | John         |
+| 6          | Alex         |
++------------+--------------+
+Subjects table:
++--------------+
+| subject_name |
++--------------+
+| Math         |
+| Physics      |
+| Programming  |
++--------------+
+Examinations table:
++------------+--------------+
+| student_id | subject_name |
++------------+--------------+
+| 1          | Math         |
+| 1          | Physics      |
+| 1          | Programming  |
+| 2          | Programming  |
+| 1          | Physics      |
+| 1          | Math         |
+| 13         | Math         |
+| 13         | Programming  |
+| 13         | Physics      |
+| 2          | Math         |
+| 1          | Math         |
++------------+--------------+
+输出:
++------------+--------------+--------------+----------------+
+| student_id | student_name | subject_name | attended_exams |
++------------+--------------+--------------+----------------+
+| 1          | Alice        | Math         | 3              |
+| 1          | Alice        | Physics      | 2              |
+| 1          | Alice        | Programming  | 1              |
+| 2          | Bob          | Math         | 1              |
+| 2          | Bob          | Physics      | 0              |
+| 2          | Bob          | Programming  | 1              |
+| 6          | Alex         | Math         | 0              |
+| 6          | Alex         | Physics      | 0              |
+| 6          | Alex         | Programming  | 0              |
+| 13         | John         | Math         | 1              |
+| 13         | John         | Physics      | 1              |
+| 13         | John         | Programming  | 1              |
++------------+--------------+--------------+----------------+
+解释:
+结果表需包含所有学生和所有科目(即便测试次数为0):
+Alice 参加了 3 次数学测试, 2 次物理测试,以及 1 次编程测试;
+Bob 参加了 1 次数学测试, 1 次编程测试,没有参加物理测试;
+Alex 啥测试都没参加;
+John  参加了数学、物理、编程测试各 1 次。
+
diff --git a/leetcode-cn/problem (Chinese)/寻找二叉搜索树中的目标节点 [er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof].html b/leetcode-cn/problem (Chinese)/寻找二叉搜索树中的目标节点 [er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof].html new file mode 100644 index 00000000..6fa46400 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/寻找二叉搜索树中的目标节点 [er-cha-sou-suo-shu-de-di-kda-jie-dian-lcof].html @@ -0,0 +1,42 @@ +

某公司组织架构以二叉搜索树形式记录,节点值为处于该职位的员工编号。请返回第 cnt 大的员工编号。

+ +

 

+ +

示例 1:

+ +

+ +
+输入:root = [7, 3, 9, 1, 5], cnt = 2
+       7
+      / \
+     3   9
+    / \
+   1   5
+输出:7
+
+ +

示例 2:

+ +

+ +
+输入: root = [10, 5, 15, 2, 7, null, 20, 1, null, 6, 8], cnt = 4
+       10
+      / \
+     5   15
+    / \    \
+   2   7    20
+  /   / \ 
+ 1   6   8
+输出: 8
+ +

 

+ +

提示:

+ +
    +
  • 1 ≤ cnt ≤ 二叉搜索树元素个数
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/寻找文件副本 [shu-zu-zhong-zhong-fu-de-shu-zi-lcof].html b/leetcode-cn/problem (Chinese)/寻找文件副本 [shu-zu-zhong-zhong-fu-de-shu-zi-lcof].html new file mode 100644 index 00000000..edf2f2a3 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/寻找文件副本 [shu-zu-zhong-zhong-fu-de-shu-zi-lcof].html @@ -0,0 +1,21 @@ +

设备中存有 n 个文件,文件 id 记于数组 documents。若文件 id 相同,则定义为该文件存在副本。请返回任一存在副本的文件 id

+ +

 

+ +

示例 1:

+ +
+输入:documents = [2, 5, 3, 0, 5, 0]
+输出:0 或 5
+
+ +

 

+ +

提示:

+ +
    +
  • 0 ≤ documents[i] ≤ n-1
  • +
  • 2 <= n <= 100000
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/寻找目标值 - 二维数组 [er-wei-shu-zu-zhong-de-cha-zhao-lcof].html b/leetcode-cn/problem (Chinese)/寻找目标值 - 二维数组 [er-wei-shu-zu-zhong-de-cha-zhao-lcof].html new file mode 100644 index 00000000..9e7731a1 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/寻找目标值 - 二维数组 [er-wei-shu-zu-zhong-de-cha-zhao-lcof].html @@ -0,0 +1,43 @@ +

m*n 的二维数组 plants 记录了园林景观的植物排布情况,具有以下特性:

+ +
    +
  • 每行中,每棵植物的右侧相邻植物不矮于该植物;
  • +
  • 每列中,每棵植物的下侧相邻植物不矮于该植物。
  • +
+ +

 

+ +

请判断 plants 中是否存在目标高度值 target

+ +

 

+ +

示例 1:

+ +
+输入:plants = [[2,3,6,8],[4,5,8,9],[5,9,10,12]], target = 8
+
+输出:true
+
+ +

 

+ +

示例 2:

+ +
+输入:plants = [[1,3,5],[2,5,7]], target = 4
+
+输出:false
+
+ +

 

+ +

提示:

+ +
    +
  • 0 <= n <= 1000
  • +
  • 0 <= m <= 1000
  • +
+ +

注意:本题与主站 240 题相同:https://leetcode-cn.com/problems/search-a-2d-matrix-ii/

+ +

 

diff --git a/leetcode-cn/problem (Chinese)/将二叉搜索树转化为排序的双向链表 [er-cha-sou-suo-shu-yu-shuang-xiang-lian-biao-lcof].html b/leetcode-cn/problem (Chinese)/将二叉搜索树转化为排序的双向链表 [er-cha-sou-suo-shu-yu-shuang-xiang-lian-biao-lcof].html new file mode 100644 index 00000000..2142ae96 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/将二叉搜索树转化为排序的双向链表 [er-cha-sou-suo-shu-yu-shuang-xiang-lian-biao-lcof].html @@ -0,0 +1,54 @@ +

将一个 二叉搜索树 就地转化为一个 已排序的双向循环链表

+ +

对于双向循环列表,你可以将左右孩子指针作为双向循环链表的前驱和后继指针,第一个节点的前驱是最后一个节点,最后一个节点的后继是第一个节点。

+ +

特别地,我们希望可以 就地 完成转换操作。当转化完成以后,树中节点的左指针需要指向前驱,树中节点的右指针需要指向后继。还需要返回链表中最小元素的指针。

+ +

 

+ +

示例 1:

+ +
+输入:root = [4,2,5,1,3] 
+
+
+输出:[1,2,3,4,5]
+
+解释:下图显示了转化后的二叉搜索树,实线表示后继关系,虚线表示前驱关系。
+
+
+ +

示例 2:

+ +
+输入:root = [2,1,3]
+输出:[1,2,3]
+
+ +

示例 3:

+ +
+输入:root = []
+输出:[]
+解释:输入是空树,所以输出也是空链表。
+
+ +

示例 4:

+ +
+输入:root = [1]
+输出:[1]
+
+ +

 

+ +

提示:

+ +
    +
  • -1000 <= Node.val <= 1000
  • +
  • Node.left.val < Node.val < Node.right.val
  • +
  • Node.val 的所有值都是独一无二的
  • +
  • 0 <= Number of Nodes <= 2000
  • +
+ +

注意:本题与主站 426 题相同:https://leetcode-cn.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list/

diff --git a/leetcode-cn/problem (Chinese)/平均售价 [average-selling-price].html b/leetcode-cn/problem (Chinese)/平均售价 [average-selling-price].html new file mode 100644 index 00000000..a0d734b2 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/平均售价 [average-selling-price].html @@ -0,0 +1,73 @@ +

表:Prices

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| product_id    | int     |
+| start_date    | date    |
+| end_date      | date    |
+| price         | int     |
++---------------+---------+
+(product_id,start_date,end_date) 是 prices 表的主键(具有唯一值的列的组合)。
+prices 表的每一行表示的是某个产品在一段时期内的价格。
+每个产品的对应时间段是不会重叠的,这也意味着同一个产品的价格时段不会出现交叉。
+ +

 

+ +

表:UnitsSold

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| product_id    | int     |
+| purchase_date | date    |
+| units         | int     |
++---------------+---------+
+该表可能包含重复数据。
+表的每一行表示的是每种产品的出售日期,单位和产品 id。
+ +

 

+ +

编写解决方案以查找每种产品的平均售价。average_price 应该 四舍五入到小数点后两位

+ +

返回结果表 无顺序要求

+ +

结果格式如下例所示。

+ +

 

+ +

示例 1:

+ +
+输入:
+Prices table:
++------------+------------+------------+--------+
+| product_id | start_date | end_date   | price  |
++------------+------------+------------+--------+
+| 1          | 2019-02-17 | 2019-02-28 | 5      |
+| 1          | 2019-03-01 | 2019-03-22 | 20     |
+| 2          | 2019-02-01 | 2019-02-20 | 15     |
+| 2          | 2019-02-21 | 2019-03-31 | 30     |
++------------+------------+------------+--------+
+UnitsSold table:
++------------+---------------+-------+
+| product_id | purchase_date | units |
++------------+---------------+-------+
+| 1          | 2019-02-25    | 100   |
+| 1          | 2019-03-01    | 15    |
+| 2          | 2019-02-10    | 200   |
+| 2          | 2019-03-22    | 30    |
++------------+---------------+-------+
+输出:
++------------+---------------+
+| product_id | average_price |
++------------+---------------+
+| 1          | 6.96          |
+| 2          | 16.96         |
++------------+---------------+
+解释:
+平均售价 = 产品总价 / 销售的产品数量。
+产品 1 的平均售价 = ((100 * 5)+(15 * 20) )/ 115 = 6.96
+产品 2 的平均售价 = ((200 * 15)+(30 * 30) )/ 230 = 16.96
diff --git a/leetcode-cn/problem (Chinese)/序列重建 [ur2n8P].html b/leetcode-cn/problem (Chinese)/序列重建 [ur2n8P].html new file mode 100644 index 00000000..bd1ee0f3 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/序列重建 [ur2n8P].html @@ -0,0 +1,64 @@ +

给定一个长度为 n 的整数数组 nums ,其中 nums 是范围为 [1,n] 的整数的排列。还提供了一个 2D 整数数组 sequences ,其中 sequences[i] 是 nums 的子序列。
+检查 nums 是否是唯一的最短 超序列 。最短 超序列长度最短 的序列,并且所有序列 sequences[i] 都是它的子序列。对于给定的数组 sequences ,可能存在多个有效的 超序列

+ +
    +
  • 例如,对于 sequences = [[1,2],[1,3]] ,有两个最短的 超序列[1,2,3][1,3,2]
  • +
  • 而对于 sequences = [[1,2],[1,3],[1,2,3]] ,唯一可能的最短 超序列[1,2,3][1,2,3,4] 是可能的超序列,但不是最短的。
  • +
+ +

如果 nums 是序列的唯一最短 超序列 ,则返回 true ,否则返回 false
+子序列 是一个可以通过从另一个序列中删除一些元素或不删除任何元素,而不改变其余元素的顺序的序列。

+ +

 

+ +

示例 1:

+ +
+输入:nums = [1,2,3], sequences = [[1,2],[1,3]]
+输出:false
+解释:有两种可能的超序列:[1,2,3]和[1,3,2]。
+序列 [1,2] 是[1,2,3]和[1,3,2]的子序列。
+序列 [1,3] 是[1,2,3]和[1,3,2]的子序列。
+因为 nums 不是唯一最短的超序列,所以返回false。
+
+ +

示例 2:

+ +
+输入:nums = [1,2,3], sequences = [[1,2]]
+输出:false
+解释:最短可能的超序列为 [1,2]。
+序列 [1,2] 是它的子序列:[1,2]。
+因为 nums 不是最短的超序列,所以返回false。
+
+ +

示例 3:

+ +
+输入:nums = [1,2,3], sequences = [[1,2],[1,3],[2,3]]
+输出:true
+解释:最短可能的超序列为[1,2,3]。
+序列 [1,2] 是它的一个子序列:[1,2,3]。
+序列 [1,3] 是它的一个子序列:[1,2,3]。
+序列 [2,3] 是它的一个子序列:[1,2,3]。
+因为 nums 是唯一最短的超序列,所以返回true。
+ +

 

+ +

提示:

+ +
    +
  • n == nums.length
  • +
  • 1 <= n <= 104
  • +
  • nums 是 [1, n] 范围内所有整数的排列
  • +
  • 1 <= sequences.length <= 104
  • +
  • 1 <= sequences[i].length <= 104
  • +
  • 1 <= sum(sequences[i].length) <= 105
  • +
  • 1 <= sequences[i][j] <= n
  • +
  • sequences 的所有数组都是 唯一
  • +
  • sequences[i] 是 nums 的一个子序列
  • +
+ +

 

+ +

注意:本题与主站 444 题相同:https://leetcode-cn.com/problems/sequence-reconstruction/

diff --git a/leetcode-cn/problem (Chinese)/库存管理 I [xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof].html b/leetcode-cn/problem (Chinese)/库存管理 I [xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof].html new file mode 100644 index 00000000..ed733a7e --- /dev/null +++ b/leetcode-cn/problem (Chinese)/库存管理 I [xuan-zhuan-shu-zu-de-zui-xiao-shu-zi-lcof].html @@ -0,0 +1,32 @@ +

仓库管理员以数组 stock 形式记录商品库存表。stock[i] 表示商品 id,可能存在重复。原库存表按商品 id 升序排列。现因突发情况需要进行商品紧急调拨,管理员将这批商品 id 提前依次整理至库存表最后。请你找到并返回库存表中编号的 最小的元素 以便及时记录本次调拨。

+ +

 

+ +

示例 1:

+ +
+输入:stock = [4,5,8,3,4]
+输出:3
+
+ +

示例 2:

+ +
+输入:stock = [5,7,9,1,2]
+输出:1
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= stock.length <= 5000
  • +
  • -5000 <= stock[i] <= 5000
  • +
+ +

 

+ +

注意:本题与主站 154 题相同:https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array-ii/

+ +

 

diff --git a/leetcode-cn/problem (Chinese)/库存管理 II [shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof].html b/leetcode-cn/problem (Chinese)/库存管理 II [shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof].html new file mode 100644 index 00000000..7f6b9199 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/库存管理 II [shu-zu-zhong-chu-xian-ci-shu-chao-guo-yi-ban-de-shu-zi-lcof].html @@ -0,0 +1,22 @@ +

仓库管理员以数组 stock 形式记录商品库存表。stock[i] 表示商品 id,可能存在重复。请返回库存表中数量大于 stock.length / 2 的商品 id

+ +

 

+ +

示例 1:

+ +
+输入: stock = [6, 1, 3, 1, 1, 1]
+输出: 1
+ +

 

+ +

限制:

+ +
    +
  • 1 <= stock.length <= 50000
  • +
  • 给定数组为非空数组,且存在结果数字
  • +
+ +

 

+ +

注意:本题与主站 169 题相同:https://leetcode-cn.com/problems/majority-element/

diff --git a/leetcode-cn/problem (Chinese)/库存管理 III [zui-xiao-de-kge-shu-lcof].html b/leetcode-cn/problem (Chinese)/库存管理 III [zui-xiao-de-kge-shu-lcof].html new file mode 100644 index 00000000..ceb6335c --- /dev/null +++ b/leetcode-cn/problem (Chinese)/库存管理 III [zui-xiao-de-kge-shu-lcof].html @@ -0,0 +1,27 @@ +

仓库管理员以数组 stock 形式记录商品库存表,其中 stock[i] 表示对应商品库存余量。请返回库存余量最少的 cnt 个商品余量,返回 顺序不限

+ +

 

+ +

示例 1:

+ +
+输入:stock = [2,5,7,4], cnt = 1
+输出:[2]
+
+ +

示例 2:

+ +
+输入:stock = [0,2,3,6], cnt = 2
+输出:[0,2] 或 [2,0]
+ +

 

+ +

提示:

+ +
    +
  • 0 <= cnt <= stock.length <= 10000
    + 0 <= stock[i] <= 10000
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/彩灯装饰记录 I [cong-shang-dao-xia-da-yin-er-cha-shu-lcof].html b/leetcode-cn/problem (Chinese)/彩灯装饰记录 I [cong-shang-dao-xia-da-yin-er-cha-shu-lcof].html new file mode 100644 index 00000000..aea69e23 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/彩灯装饰记录 I [cong-shang-dao-xia-da-yin-er-cha-shu-lcof].html @@ -0,0 +1,22 @@ +

一棵圣诞树记作根节点为 root 的二叉树,节点值为该位置装饰彩灯的颜色编号。请按照从 的顺序返回每一层彩灯编号。

+ +

 

+ +

示例 1:

+ +

+ +
+输入:root = [8,17,21,18,null,null,6]
+输出:[8,17,21,18,6]
+
+ +

 

+ +

提示:

+ +
    +
  1. 节点总数 <= 1000
  2. +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/彩灯装饰记录 II [cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof].html b/leetcode-cn/problem (Chinese)/彩灯装饰记录 II [cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof].html new file mode 100644 index 00000000..b73f9f78 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/彩灯装饰记录 II [cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof].html @@ -0,0 +1,22 @@ +

一棵圣诞树记作根节点为 root 的二叉树,节点值为该位置装饰彩灯的颜色编号。请按照从左到右的顺序返回每一层彩灯编号,每一层的结果记录于一行。

+ +

 

+ +

示例 1:

+ +

+ +
+输入:root = [8,17,21,18,null,null,6]
+输出:[[8],[17,21],[18,6]]
+
+ +

提示:

+ +
    +
  1. 节点总数 <= 1000
  2. +
+ +

注意:本题与主站 102 题相同:https://leetcode-cn.com/problems/binary-tree-level-order-traversal/

+ +

 

diff --git a/leetcode-cn/problem (Chinese)/彩灯装饰记录 III [cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof].html b/leetcode-cn/problem (Chinese)/彩灯装饰记录 III [cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof].html new file mode 100644 index 00000000..ad849af8 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/彩灯装饰记录 III [cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof].html @@ -0,0 +1,27 @@ +

一棵圣诞树记作根节点为 root 的二叉树,节点值为该位置装饰彩灯的颜色编号。请按照如下规则记录彩灯装饰结果:

+ +
    +
  • 第一层按照从左到右的顺序记录
  • +
  • 除第一层外每一层的记录顺序均与上一层相反。即第一层为从左到右,第二层为从右到左。
  • +
+ +

 

+ +

示例 1:

+ +

+ +
+输入:root = [8,17,21,18,null,null,6]
+输出:[[8],[21,17],[18,6]]
+
+ +

 

+ +

提示:

+ +
    +
  • 节点总数 <= 1000
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/所有可能的真二叉树 [all-possible-full-binary-trees].html b/leetcode-cn/problem (Chinese)/所有可能的真二叉树 [all-possible-full-binary-trees].html new file mode 100644 index 00000000..2420eb45 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/所有可能的真二叉树 [all-possible-full-binary-trees].html @@ -0,0 +1,29 @@ +

给你一个整数 n ,请你找出所有可能含 n 个节点的 真二叉树 ,并以列表形式返回。答案中每棵树的每个节点都必须符合 Node.val == 0

+ +

答案的每个元素都是一棵真二叉树的根节点。你可以按 任意顺序 返回最终的真二叉树列表

+ +

真二叉树 是一类二叉树,树中每个节点恰好有 02 个子节点。

+ +

 

+ +

示例 1:

+ +
+输入:n = 7
+输出:[[0,0,0,null,null,0,0,null,null,0,0],[0,0,0,null,null,0,0,0,0],[0,0,0,0,0,0,0],[0,0,0,0,0,null,null,null,null,0,0],[0,0,0,0,0,null,null,0,0]]
+
+ +

示例 2:

+ +
+输入:n = 3
+输出:[[0,0,0]]
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= n <= 20
  • +
diff --git a/leetcode-cn/problem (Chinese)/找出字符串中第一个匹配项的下标 [find-the-index-of-the-first-occurrence-in-a-string].html b/leetcode-cn/problem (Chinese)/找出字符串中第一个匹配项的下标 [find-the-index-of-the-first-occurrence-in-a-string].html new file mode 100644 index 00000000..f2376e56 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/找出字符串中第一个匹配项的下标 [find-the-index-of-the-first-occurrence-in-a-string].html @@ -0,0 +1,29 @@ +

给你两个字符串 haystackneedle ,请你在 haystack 字符串中找出 needle 字符串的第一个匹配项的下标(下标从 0 开始)。如果 needle 不是 haystack 的一部分,则返回  -1

+ +

 

+ +

示例 1:

+ +
+输入:haystack = "sadbutsad", needle = "sad"
+输出:0
+解释:"sad" 在下标 0 和 6 处匹配。
+第一个匹配项的下标是 0 ,所以返回 0 。
+
+ +

示例 2:

+ +
+输入:haystack = "leetcode", needle = "leeto"
+输出:-1
+解释:"leeto" 没有在 "leetcode" 中出现,所以返回 -1 。
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= haystack.length, needle.length <= 104
  • +
  • haystackneedle 仅由小写英文字符组成
  • +
diff --git a/leetcode-cn/problem (Chinese)/找出第 K 小的数对距离 [find-k-th-smallest-pair-distance].html b/leetcode-cn/problem (Chinese)/找出第 K 小的数对距离 [find-k-th-smallest-pair-distance].html new file mode 100644 index 00000000..79d659ba --- /dev/null +++ b/leetcode-cn/problem (Chinese)/找出第 K 小的数对距离 [find-k-th-smallest-pair-distance].html @@ -0,0 +1,42 @@ +

数对 (a,b) 由整数 ab 组成,其数对距离定义为 ab 的绝对差值。

+ +

给你一个整数数组 nums 和一个整数 k ,数对由 nums[i]nums[j] 组成且满足 0 <= i < j < nums.length 。返回 所有数对距离中k 小的数对距离。

+ +

 

+ +

示例 1:

+ +
+输入:nums = [1,3,1], k = 1
+输出:0
+解释:数对和对应的距离如下:
+(1,3) -> 2
+(1,1) -> 0
+(3,1) -> 2
+距离第 1 小的数对是 (1,1) ,距离为 0 。
+
+ +

示例 2:

+ +
+输入:nums = [1,1,1], k = 2
+输出:0
+
+ +

示例 3:

+ +
+输入:nums = [1,6,1], k = 3
+输出:5
+
+ +

 

+ +

提示:

+ +
    +
  • n == nums.length
  • +
  • 2 <= n <= 104
  • +
  • 0 <= nums[i] <= 106
  • +
  • 1 <= k <= n * (n - 1) / 2
  • +
diff --git a/leetcode-cn/problem (Chinese)/找到第 k 位数字 [shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof].html b/leetcode-cn/problem (Chinese)/找到第 k 位数字 [shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof].html new file mode 100644 index 00000000..c1d8802b --- /dev/null +++ b/leetcode-cn/problem (Chinese)/找到第 k 位数字 [shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof].html @@ -0,0 +1,29 @@ +

某班级学号记录系统发生错乱,原整数学号序列 [0,1,2,3,4,...] 分隔符丢失后变为 01234... 的字符序列。请实现一个函数返回该字符序列中的第 k 位数字。

+ +

 

+ +

示例 1:

+ +
+输入:k = 5
+输出:5
+
+ +

示例 2:

+ +
+输入:k = 12
+输出:1
+解释:第 12 位数字在序列 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... 里是 1 ,它是 11 的一部分。
+ +

 

+ +

提示:

+ +
    +
  • 0 <= k < 231
  • +
+ +

注意:本题与主站 400 题相同:https://leetcode-cn.com/problems/nth-digit/

+ +

 

diff --git a/leetcode-cn/problem (Chinese)/把字符串转换成整数 (atoi) [ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof].html b/leetcode-cn/problem (Chinese)/把字符串转换成整数 (atoi) [ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof].html new file mode 100644 index 00000000..36eec751 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/把字符串转换成整数 (atoi) [ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof].html @@ -0,0 +1,83 @@ +

请你来实现一个 myAtoi(string s) 函数,使其能将字符串转换成一个 32 位有符号整数(类似 C/C++ 中的 atoi 函数)。

+ +

函数 myAtoi(string s) 的算法如下:

+ +
    +
  1. 读入字符串并丢弃无用的前导空格
  2. +
  3. 检查下一个字符(假设还未到字符末尾)为正还是负号,读取该字符(如果有)。 确定最终结果是负数还是正数。 如果两者都不存在,则假定结果为正。
  4. +
  5. 读入下一个字符,直到到达下一个非数字字符或到达输入的结尾。字符串的其余部分将被忽略。
  6. +
  7. 将前面步骤读入的这些数字转换为整数(即,"123" -> 123, "0032" -> 32)。如果没有读入数字,则整数为 0 。必要时更改符号(从步骤 2 开始)。
  8. +
  9. 如果整数数超过 32 位有符号整数范围 [−231,  231 − 1] ,需要截断这个整数,使其保持在这个范围内。具体来说,小于 −231 的整数应该被固定为 −231 ,大于 231 − 1 的整数应该被固定为 231 − 1
  10. +
  11. 返回整数作为最终结果。
  12. +
+ +

注意:

+ +
    +
  • 本题中的空白字符只包括空格字符 ' '
  • +
  • 除前导空格或数字后的其余字符串外,请勿忽略 任何其他字符。
  • +
+ +

 

+ +

示例 1:

+ +
+输入:s = "42"
+输出:42
+解释:加粗的字符串为已经读入的字符,插入符号是当前读取的字符。
+第 1 步:"42"(当前没有读入字符,因为没有前导空格)
+         ^
+第 2 步:"42"(当前没有读入字符,因为这里不存在 '-' 或者 '+')
+         ^
+第 3 步:"42"(读入 "42")
+           ^
+解析得到整数 42 。
+由于 "42" 在范围 [-231, 231 - 1] 内,最终结果为 42 。
+ +

示例 2:

+ +
+输入:s = "   -42"
+输出:-42
+解释:
+第 1 步:"   -42"(读入前导空格,但忽视掉)
+            ^
+第 2 步:"   -42"(读入 '-' 字符,所以结果应该是负数)
+             ^
+第 3 步:"   -42"(读入 "42")
+               ^
+解析得到整数 -42 。
+由于 "-42" 在范围 [-231, 231 - 1] 内,最终结果为 -42 。
+
+ +

示例 3:

+ +
+输入:s = "4193 with words"
+输出:4193
+解释:
+第 1 步:"4193 with words"(当前没有读入字符,因为没有前导空格)
+         ^
+第 2 步:"4193 with words"(当前没有读入字符,因为这里不存在 '-' 或者 '+')
+         ^
+第 3 步:"4193 with words"(读入 "4193";由于下一个字符不是一个数字,所以读入停止)
+             ^
+解析得到整数 4193 。
+由于 "4193" 在范围 [-231, 231 - 1] 内,最终结果为 4193 。
+
+ +

 

+ +

提示:

+ +
    +
  • 0 <= s.length <= 200
  • +
  • s 由英文字母(大写和小写)、数字(0-9)、' ''+''-''.' 组成
  • +
+ +

 

+ +

注意:本题与主站 8 题相同:https://leetcode-cn.com/problems/string-to-integer-atoi/

+ +

 

diff --git a/leetcode-cn/problem (Chinese)/报数 [da-yin-cong-1dao-zui-da-de-nwei-shu-lcof].html b/leetcode-cn/problem (Chinese)/报数 [da-yin-cong-1dao-zui-da-de-nwei-shu-lcof].html new file mode 100644 index 00000000..e3603fe4 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/报数 [da-yin-cong-1dao-zui-da-de-nwei-shu-lcof].html @@ -0,0 +1,9 @@ +

实现一个十进制数字报数程序,请按照数字从小到大的顺序返回一个整数数列,该数列从数字 1 开始,到最大的正整数 cnt 位数字结束。

+ +

 

+ +

示例 1:

+ +
+输入:cnt = 2
+输出:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99]
diff --git a/leetcode-cn/problem (Chinese)/招式拆解 I [zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof].html b/leetcode-cn/problem (Chinese)/招式拆解 I [zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof].html new file mode 100644 index 00000000..a71272f5 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/招式拆解 I [zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof].html @@ -0,0 +1,43 @@ +

某套连招动作记作序列 arr,其中 arr[i] 为第 i 个招式的名字。请返回 arr 中最多可以出连续不重复的多少个招式。

+ +

 

+ +

示例 1:

+ +
+输入: arr = "dbascDdad"
+输出: 6
+解释: 因为连续且最长的招式序列是 "dbascD" 或 "bascDd",所以其长度为 6。
+
+ +

示例 2:

+ +
+输入: arr = "KKK"
+输出: 1
+解释: 因为无重复字符的最长子串是 "K",所以其长度为 1。
+
+ +

示例 3:

+ +
+输入: arr = "pwwkew"
+输出: 3
+解释: 因为连续且最长的招式序列是 "wke",所以其长度为 3。     
+请注意区分 子串子序列 的概念:你的答案必须是 连续招式 的长度,也就是 子串。而 "pwke" 是一个非连续的 子序列,不是 子串。
+
+ +

 

+ +

提示:

+ +
    +
  • 0 <= arr.length <= 40000
  • +
  • arr 由英文字母、数字、符号和空格组成。
  • +
+ +

 

+ +

注意:本题与主站 3 题相同:https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/

+ +

 

diff --git a/leetcode-cn/problem (Chinese)/招式拆解 II [di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof].html b/leetcode-cn/problem (Chinese)/招式拆解 II [di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof].html new file mode 100644 index 00000000..3022ff44 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/招式拆解 II [di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof].html @@ -0,0 +1,23 @@ +

某套连招动作记作仅由小写字母组成的序列 arr,其中 arr[i]i 个招式的名字。请返回第一个只出现一次的招式名称,如不存在请返回空格。

+ +

 

+ +

示例 1:

+ +
+输入:arr = "abbccdeff"
+输出:'a'
+
+ +

示例 2:

+ +
+输入:arr = "ccdd"
+输出:' '
+
+ +

 

+ +

限制:

+ +

0 <= arr.length <= 50000

diff --git a/leetcode-cn/problem (Chinese)/指定日期的产品价格 [product-price-at-a-given-date].html b/leetcode-cn/problem (Chinese)/指定日期的产品价格 [product-price-at-a-given-date].html new file mode 100644 index 00000000..a9828e7e --- /dev/null +++ b/leetcode-cn/problem (Chinese)/指定日期的产品价格 [product-price-at-a-given-date].html @@ -0,0 +1,46 @@ +

产品数据表: Products

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| product_id    | int     |
+| new_price     | int     |
+| change_date   | date    |
++---------------+---------+
+(product_id, change_date) 是此表的主键(具有唯一值的列组合)。
+这张表的每一行分别记录了 某产品 在某个日期 更改后 的新价格。
+ +

 

+ +

编写一个解决方案,找出在 2019-08-16 时全部产品的价格,假设所有产品在修改前的价格都是 10

+ +

任意顺序 返回结果表。

+ +

结果格式如下例所示。

+ +

 

+ +

示例 1:

+ +
+输入:
+Products 表:
++------------+-----------+-------------+
+| product_id | new_price | change_date |
++------------+-----------+-------------+
+| 1          | 20        | 2019-08-14  |
+| 2          | 50        | 2019-08-14  |
+| 1          | 30        | 2019-08-15  |
+| 1          | 35        | 2019-08-16  |
+| 2          | 65        | 2019-08-17  |
+| 3          | 20        | 2019-08-18  |
++------------+-----------+-------------+
+输出:
++------------+-------+
+| product_id | price |
++------------+-------+
+| 2          | 50    |
+| 1          | 35    |
+| 3          | 10    |
++------------+-------+
diff --git a/leetcode-cn/problem (Chinese)/按分类统计薪水 [count-salary-categories].html b/leetcode-cn/problem (Chinese)/按分类统计薪水 [count-salary-categories].html new file mode 100644 index 00000000..ba6859f7 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/按分类统计薪水 [count-salary-categories].html @@ -0,0 +1,58 @@ +

表: Accounts

+ +
++-------------+------+
+| 列名        | 类型  |
++-------------+------+
+| account_id  | int  |
+| income      | int  |
++-------------+------+
+在 SQL 中,account_id 是这个表的主键。
+每一行都包含一个银行帐户的月收入的信息。
+
+ +

 

+ +

查询每个工资类别的银行账户数量。 工资类别如下:

+ +
    +
  • "Low Salary":所有工资 严格低于 20000 美元。
  • +
  • "Average Salary"包含 范围内的所有工资 [$20000, $50000]
  • +
  • +

    "High Salary":所有工资 严格大于 50000 美元。

    +
  • +
+ +

结果表 必须 包含所有三个类别。 如果某个类别中没有帐户,则报告 0

+ +

任意顺序 返回结果表。

+ +

查询结果格式如下示例。

+ +

 

+ +

示例 1:

+ +
+输入:
+Accounts 表:
++------------+--------+
+| account_id | income |
++------------+--------+
+| 3          | 108939 |
+| 2          | 12747  |
+| 8          | 87709  |
+| 6          | 91796  |
++------------+--------+
+输出:
++----------------+----------------+
+| category       | accounts_count |
++----------------+----------------+
+| Low Salary     | 1              |
+| Average Salary | 0              |
+| High Salary    | 3              |
++----------------+----------------+
+解释:
+低薪: 有一个账户 2.
+中等薪水: 没有.
+高薪: 有三个账户,他们是 3, 6和 8.
diff --git a/leetcode-cn/problem (Chinese)/按字典序排列最小的等效字符串 [lexicographically-smallest-equivalent-string].html b/leetcode-cn/problem (Chinese)/按字典序排列最小的等效字符串 [lexicographically-smallest-equivalent-string].html new file mode 100644 index 00000000..97ccbdb4 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/按字典序排列最小的等效字符串 [lexicographically-smallest-equivalent-string].html @@ -0,0 +1,55 @@ +

给出长度相同的两个字符串s1 和 s2 ,还有一个字符串 baseStr 。

+ +

其中  s1[i] 和 s2[i]  是一组等价字符。

+ +
    +
  • 举个例子,如果 s1 = "abc" 且 s2 = "cde",那么就有 'a' == 'c', 'b' == 'd', 'c' == 'e'
  • +
+ +

等价字符遵循任何等价关系的一般规则:

+ +
    +
  •  自反性 'a' == 'a'
  • +
  •  对称性 'a' == 'b' 则必定有 'b' == 'a'
  • +
  •  传递性'a' == 'b''b' == 'c' 就表明 'a' == 'c'
  • +
+ +

例如, s1 = "abc" 和 s2 = "cde" 的等价信息和之前的例子一样,那么 baseStr = "eed" , "acd" 或 "aab",这三个字符串都是等价的,而 "aab" 是 baseStr 的按字典序最小的等价字符串

+ +

利用 s1 和 s2 的等价信息,找出并返回 baseStr 的按字典序排列最小的等价字符串。

+ +

 

+ +

示例 1:

+ +
+输入:s1 = "parker", s2 = "morris", baseStr = "parser"
+输出:"makkek"
+解释:根据 AB 中的等价信息,我们可以将这些字符分为 [m,p], [a,o], [k,r,s], [e,i] 共 4 组。每组中的字符都是等价的,并按字典序排列。所以答案是 "makkek"。
+
+ +

示例 2:

+ +
+输入:s1 = "hello", s2 = "world", baseStr = "hold"
+输出:"hdld"
+解释:根据 AB 中的等价信息,我们可以将这些字符分为 [h,w], [d,e,o], [l,r] 共 3 组。所以只有 S 中的第二个字符 'o' 变成 'd',最后答案为 "hdld"。
+
+ +

示例 3:

+ +
+输入:s1 = "leetcode", s2 = "programs", baseStr = "sourcecode"
+输出:"aauaaaaada"
+解释:我们可以把 A 和 B 中的等价字符分为 [a,o,e,r,s,c], [l,p], [g,t][d,m] 共 4 组,因此 S 中除了 'u''d' 之外的所有字母都转化成了 'a',最后答案为 "aauaaaaada"。
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= s1.length, s2.length, baseStr <= 1000
  • +
  • s1.length == s2.length
  • +
  • 字符串s1s2, and baseStr 仅由从 'a' 到 'z' 的小写英文字母组成。
  • +
diff --git a/leetcode-cn/problem (Chinese)/按规则计算统计结果 [gou-jian-cheng-ji-shu-zu-lcof].html b/leetcode-cn/problem (Chinese)/按规则计算统计结果 [gou-jian-cheng-ji-shu-zu-lcof].html new file mode 100644 index 00000000..a3b0f30a --- /dev/null +++ b/leetcode-cn/problem (Chinese)/按规则计算统计结果 [gou-jian-cheng-ji-shu-zu-lcof].html @@ -0,0 +1,21 @@ +

为了深入了解这些生物群体的生态特征,你们进行了大量的实地观察和数据采集。数组 arrayA 记录了各个生物群体数量数据,其中 arrayA[i] 表示第 i 个生物群体的数量。请返回一个数组 arrayB,该数组为基于数组 arrayA 中的数据计算得出的结果,其中 arrayB[i] 表示将第 i 个生物群体的数量从总体中排除后的其他数量的乘积。

+ +

 

+ +

示例 1:

+ +
+输入:arrayA = [2, 4, 6, 8, 10]
+输出:[1920, 960, 640, 480, 384]
+
+ +

 

+ +

提示:

+ +
    +
  • 所有元素乘积之和不会溢出 32 位整数
  • +
  • arrayA.length <= 100000
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/换水问题 [water-bottles].html b/leetcode-cn/problem (Chinese)/换水问题 [water-bottles].html new file mode 100644 index 00000000..42491593 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/换水问题 [water-bottles].html @@ -0,0 +1,40 @@ +

超市正在促销,你可以用 numExchange 个空水瓶从超市兑换一瓶水。最开始,你一共购入了 numBottles 瓶水。

+ +

如果喝掉了水瓶中的水,那么水瓶就会变成空的。

+ +

给你两个整数 numBottlesnumExchange ,返回你 最多 可以喝到多少瓶水。

+ +

 

+ +

示例 1:

+ +

+ +
+输入:numBottles = 9, numExchange = 3
+输出:13
+解释:你可以用 3 个空瓶兑换 1 瓶水。
+所以最多能喝到 9 + 3 + 1 = 13 瓶水。
+
+ +

示例 2:

+ +

+ +
+输入:numBottles = 15, numExchange = 4
+输出:19
+解释:你可以用 4 个空瓶兑换 1 瓶水。
+所以最多能喝到 15 + 3 + 1 = 19 瓶水。
+
+ +

 

+ +

 

+ +

提示:

+ +
    +
  • 1 <= numBottles <= 100
  • +
  • 2 <= numExchange <= 100
  • +
diff --git a/leetcode-cn/problem (Chinese)/推理二叉树 [zhong-jian-er-cha-shu-lcof].html b/leetcode-cn/problem (Chinese)/推理二叉树 [zhong-jian-er-cha-shu-lcof].html new file mode 100644 index 00000000..fcf0949c --- /dev/null +++ b/leetcode-cn/problem (Chinese)/推理二叉树 [zhong-jian-er-cha-shu-lcof].html @@ -0,0 +1,46 @@ +

某二叉树的先序遍历结果记录于整数数组 preorder,它的中序遍历结果记录于整数数组 inorder。请根据 preorderinorder 的提示构造出这棵二叉树并返回其根节点。

+ +

 

+ +

注意:preorderinorder 中均不含重复数字。

+ +

 

+ +

示例 1:

+ +

+ +
+输入: preorder = [3,9,20,15,7], inorder = [9,3,15,20,7]
+
+输出: [3,9,20,null,null,15,7]
+
+ +

 

+ +

示例 2:

+ +
+输入: preorder = [-1], inorder = [-1]
+
+输出: [-1]
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= preorder.length <= 3000
  • +
  • inorder.length == preorder.length
  • +
  • -3000 <= preorder[i], inorder[i] <= 3000
  • +
  • inorder 均出现在 preorder
  • +
  • preorder 保证 为二叉树的前序遍历序列
  • +
  • inorder 保证 为二叉树的中序遍历序列
  • +
+ +

 

+ +

注意:本题与主站 105 题重复:https://leetcode-cn.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal/

+ +

 

diff --git a/leetcode-cn/problem (Chinese)/撞色搭配 [shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof].html b/leetcode-cn/problem (Chinese)/撞色搭配 [shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof].html new file mode 100644 index 00000000..1687b316 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/撞色搭配 [shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-lcof].html @@ -0,0 +1,24 @@ +

整数数组 sockets 记录了一个袜子礼盒的颜色分布情况,其中 sockets[i] 表示该袜子的颜色编号。礼盒中除了一款撞色搭配的袜子,每种颜色的袜子均有两只。请设计一个程序,在时间复杂度 O(n),空间复杂度O(1) 内找到这双撞色搭配袜子的两个颜色编号。

+ +

 

+ +

示例 1:

+ +
+输入:sockets = [4, 5, 2, 4, 6, 6]
+输出:[2,5] 或 [5,2]
+
+ +

示例 2:

+ +
+输入:sockets = [1, 2, 4, 1, 4, 3, 12, 3]
+输出:[2,12] 或 [12,2]
+ +

 

+ +

提示:

+ +
    +
  • 2 <= sockets.length <= 10000
  • +
diff --git a/leetcode-cn/problem (Chinese)/改变数据类型 [change-data-type].html b/leetcode-cn/problem (Chinese)/改变数据类型 [change-data-type].html new file mode 100644 index 00000000..2689cd4a --- /dev/null +++ b/leetcode-cn/problem (Chinese)/改变数据类型 [change-data-type].html @@ -0,0 +1,40 @@ +
+DataFrame students
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| student_id  | int    |
+| name        | object |
+| age         | int    |
+| grade       | float  |
++-------------+--------+
+
+ +

编写一个解决方案来纠正以下错误:

+ +

 grade 列被存储为浮点数,将它转换为整数。

+ +

返回结果格式如下示例所示。

+ +

 

+ +

示例 1:

+ +
+输入:
+DataFrame students:
++------------+------+-----+-------+
+| student_id | name | age | grade |
++------------+------+-----+-------+
+| 1          | Ava  | 6   | 73.0  |
+| 2          | Kate | 15  | 87.0  |
++------------+------+-----+-------+
+输出:
++------------+------+-----+-------+
+| student_id | name | age | grade |
++------------+------+-----+-------+
+| 1          | Ava  | 6   | 73    |
+| 2          | Kate | 15  | 87    |
++------------+------+-----+-------+
+解释:
+grade 列的数据类型已转换为整数。
diff --git a/leetcode-cn/problem (Chinese)/数字 1 的个数 [1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof].html b/leetcode-cn/problem (Chinese)/数字 1 的个数 [1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof].html new file mode 100644 index 00000000..b8586b47 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/数字 1 的个数 [1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof].html @@ -0,0 +1,28 @@ +

给定一个整数 num,计算所有小于等于 num 的非负整数中数字 1 出现的个数。

+ +

 

+ +

示例 1:

+ +
+输入:num = 0
+输出:0
+
+ +

示例 2:

+ +
+输入:num = 13
+输出:6
+ +

 

+ +

提示:

+ +
    +
  • 0 <= num < 109
  • +
+ +

注意:本题与主站 233 题相同:https://leetcode-cn.com/problems/number-of-digit-one/

+ +

 

diff --git a/leetcode-cn/problem (Chinese)/数据选取 [select-data].html b/leetcode-cn/problem (Chinese)/数据选取 [select-data].html new file mode 100644 index 00000000..f5ae7cf0 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/数据选取 [select-data].html @@ -0,0 +1,38 @@ +
+DataFrame students
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| student_id  | int    |
+| name        | object |
+| age         | int    |
++-------------+--------+
+
+
+ +

编写一个解决方案,选择 student_id = 101 的学生的 name 和 age 并输出。

+ +

返回结果格式如下示例所示。

+ +

 

+ +

示例 1:

+ +
+输入:
++------------+---------+-----+
+| student_id | name    | age |
++------------+---------+-----+
+| 101        | Ulysses | 13  |
+| 53         | William | 10  |
+| 128        | Henry   | 6   |
+| 3          | Henry   | 11  |
++------------+---------+-----+
+输出:
++---------+-----+
+| name    | age | 
++---------+-----+
+| Ulysses | 13  |
++---------+-----+
+解释:
+学生 Ulysses 的 student_id = 101,所以我们输出了他的 name 和 age。
diff --git a/leetcode-cn/problem (Chinese)/数据重塑:透视 [reshape-data-pivot].html b/leetcode-cn/problem (Chinese)/数据重塑:透视 [reshape-data-pivot].html new file mode 100644 index 00000000..3098e962 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/数据重塑:透视 [reshape-data-pivot].html @@ -0,0 +1,46 @@ +
+DataFrame weather
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| city        | object |
+| month       | object |
+| temperature | int    |
++-------------+--------+
+
+ +

编写一个解决方案,以便将数据 旋转,使得每一行代表特定月份的温度,而每个城市都是一个单独的列。

+ +

输出结果格式如下示例所示。

+ +

 

+示例 1: + +
+输入:
++--------------+----------+-------------+
+| city         | month    | temperature |
++--------------+----------+-------------+
+| Jacksonville | January  | 13          |
+| Jacksonville | February | 23          |
+| Jacksonville | March    | 38          |
+| Jacksonville | April    | 5           |
+| Jacksonville | May      | 34          |
+| ElPaso       | January  | 20          |
+| ElPaso       | February | 6           |
+| ElPaso       | March    | 26          |
+| ElPaso       | April    | 2           |
+| ElPaso       | May      | 43          |
++--------------+----------+-------------+
+输出:
++----------+--------+--------------+
+| month    | ElPaso | Jacksonville |
++----------+--------+--------------+
+| April    | 2      | 5            |
+| February | 6      | 23           |
+| January  | 20     | 13           |
+| March    | 26     | 38           |
+| May      | 43     | 34           |
++----------+--------+--------------+
+解释:
+表格被旋转,每一列代表一个城市,每一行代表特定的月份。
diff --git a/leetcode-cn/problem (Chinese)/文件组合 [he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof].html b/leetcode-cn/problem (Chinese)/文件组合 [he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof].html new file mode 100644 index 00000000..e617a534 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/文件组合 [he-wei-sde-lian-xu-zheng-shu-xu-lie-lcof].html @@ -0,0 +1,36 @@ +

待传输文件被切分成多个部分,按照原排列顺序,每部分文件编号均为一个 正整数(至少含有两个文件)。传输要求为:连续文件编号总和为接收方指定数字 target 的所有文件。请返回所有符合该要求的文件传输组合列表。

+ +

注意,返回时需遵循以下规则:

+ +
    +
  • 每种组合按照文件编号 升序 排列;
  • +
  • 不同组合按照第一个文件编号 升序 排列。
  • +
+ +

 

+ +

示例 1:

+ +
+输入:target = 12
+输出:[[3, 4, 5]]
+解释:在上述示例中,存在一个连续正整数序列的和为 12,为 [3, 4, 5]。
+
+ +

示例 2:

+ +
+输入:target = 18
+输出:[[3,4,5,6],[5,6,7]]
+解释:在上述示例中,存在两个连续正整数序列的和分别为 18,分别为 [3, 4, 5, 6] 和 [5, 6, 7]。
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= target <= 10^5
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/文物朝代判断 [bu-ke-pai-zhong-de-shun-zi-lcof].html b/leetcode-cn/problem (Chinese)/文物朝代判断 [bu-ke-pai-zhong-de-shun-zi-lcof].html new file mode 100644 index 00000000..9b260f50 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/文物朝代判断 [bu-ke-pai-zhong-de-shun-zi-lcof].html @@ -0,0 +1,30 @@ +

展览馆展出来自 13 个朝代的文物,每排展柜展出 5 个文物。某排文物的摆放情况记录于数组 places,其中 places[i] 表示处于第 i 位文物的所属朝代编号。其中,编号为 0 的朝代表示未知朝代。请判断并返回这排文物的所属朝代编号是否连续(如遇未知朝代可算作连续情况)。

+ +

 

+ +

示例 1:

+ +
+输入: places = [0, 6, 9, 0, 7]
+输出: True
+
+ +

 

+ +

示例 2:

+ +
+输入: places = [7, 8, 9, 10, 11]
+输出: True
+
+ +

 

+ +

提示:

+ +
    +
  • places.length = 5
  • +
  • 0 <= places[i] <= 13
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/斐波那契数 [fei-bo-na-qi-shu-lie-lcof].html b/leetcode-cn/problem (Chinese)/斐波那契数 [fei-bo-na-qi-shu-lie-lcof].html new file mode 100644 index 00000000..adc8fb57 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/斐波那契数 [fei-bo-na-qi-shu-lie-lcof].html @@ -0,0 +1,46 @@ +

斐波那契数 (通常用 F(n) 表示)形成的序列称为 斐波那契数列 。该数列由 01 开始,后面的每一项数字都是前面两项数字的和。也就是:

+ +
+F(0) = 0,F(1) = 1
+F(n) = F(n - 1) + F(n - 2),其中 n > 1
+
+ +

给定 n ,请计算 F(n)

+ +

答案需要取模 1e9+7(1000000007) ,如计算初始结果为:1000000008,请返回 1。

+ +

 

+ +

示例 1:

+ +
+输入:n = 2
+输出:1
+解释:F(2) = F(1) + F(0) = 1 + 0 = 1
+
+ +

示例 2:

+ +
+输入:n = 3
+输出:2
+解释:F(3) = F(2) + F(1) = 1 + 1 = 2
+
+ +

示例 3:

+ +
+输入:n = 4
+输出:3
+解释:F(4) = F(3) + F(2) = 2 + 1 = 3
+
+ +

 

+ +

提示:

+ +
    +
  • 0 <= n <= 100
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/方法链 [method-chaining].html b/leetcode-cn/problem (Chinese)/方法链 [method-chaining].html new file mode 100644 index 00000000..fa9a5304 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/方法链 [method-chaining].html @@ -0,0 +1,54 @@ +
+DataFrame animals
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| name        | object |
+| species     | object |
+| age         | int    |
+| weight      | int    |
++-------------+--------+
+
+ +

编写一个解决方案来列出体重 严格超过  100  千克的动物的名称。

+ +

按体重 降序 返回动物。

+ +

返回结果格式如下示例所示。

+ +

 

+ +

示例 1:

+ +
+输入:
+DataFrame animals:
++----------+---------+-----+--------+
+| name     | species | age | weight |
++----------+---------+-----+--------+
+| Tatiana  | Snake   | 98  | 464    |
+| Khaled   | Giraffe | 50  | 41     |
+| Alex     | Leopard | 6   | 328    |
+| Jonathan | Monkey  | 45  | 463    |
+| Stefan   | Bear    | 100 | 50     |
+| Tommy    | Panda   | 26  | 349    |
++----------+---------+-----+--------+
+输出:
++----------+
+| name     |
++----------+
+| Tatiana  |
+| Jonathan |
+| Tommy    |
+| Alex     |
++----------+
+解释:
+所有体重超过 100 的动物都应包含在结果表中。
+Tatiana 的体重为 464,Jonathan 的体重为 463,Tommy 的体重为 349,Alex 的体重为 328。
+结果应按体重降序排序。
+ +

 

+ +

在 Pandas 中,方法链 允许我们在 DataFrame 上执行操作,而无需将每个操作拆分成单独的行或创建多个临时变量。

+ +

你能用 一行 代码的方法链完成这个任务吗?

diff --git a/leetcode-cn/problem (Chinese)/无效的推文 [invalid-tweets].html b/leetcode-cn/problem (Chinese)/无效的推文 [invalid-tweets].html new file mode 100644 index 00000000..47a30ba0 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/无效的推文 [invalid-tweets].html @@ -0,0 +1,44 @@ +

表:Tweets

+ +
++----------------+---------+
+| Column Name    | Type    |
++----------------+---------+
+| tweet_id       | int     |
+| content        | varchar |
++----------------+---------+
+在 SQL 中,tweet_id 是这个表的主键。
+这个表包含某社交媒体 App 中所有的推文。
+ +

 

+ +

查询所有无效推文的编号(ID)。当推文内容中的字符数严格大于 15 时,该推文是无效的。

+ +

任意顺序返回结果表。

+ +

查询结果格式如下所示:

+ +

 

+ +

示例 1:

+ +
+输入:
+Tweets 表:
++----------+----------------------------------+
+| tweet_id | content                          |
++----------+----------------------------------+
+| 1        | Vote for Biden                   |
+| 2        | Let us make America great again! |
++----------+----------------------------------+
+
+输出:
++----------+
+| tweet_id |
++----------+
+| 2        |
++----------+
+解释:
+推文 1 的长度 length = 14。该推文是有效的。
+推文 2 的长度 length = 32。该推文是无效的。
+
diff --git a/leetcode-cn/problem (Chinese)/显示前三行 [display-the-first-three-rows].html b/leetcode-cn/problem (Chinese)/显示前三行 [display-the-first-three-rows].html new file mode 100644 index 00000000..f52362b1 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/显示前三行 [display-the-first-three-rows].html @@ -0,0 +1,41 @@ +
+DataFrame: employees
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| employee_id | int    |
+| name        | object |
+| department  | object |
+| salary      | int    |
++-------------+--------+
+
+ +

编写一个解决方案,显示这个 DataFrame 的 前  3 行。

+ +

 

+ +

示例 1:

+ +
+输入:
+DataFrame employees
++-------------+-----------+-----------------------+--------+
+| employee_id | name      | department            | salary |
++-------------+-----------+-----------------------+--------+
+| 3           | Bob       | Operations            | 48675  |
+| 90          | Alice     | Sales                 | 11096  |
+| 9           | Tatiana   | Engineering           | 33805  |
+| 60          | Annabelle | InformationTechnology | 37678  |
+| 49          | Jonathan  | HumanResources        | 23793  |
+| 43          | Khaled    | Administration        | 40454  |
++-------------+-----------+-----------------------+--------+
+输出:
++-------------+---------+-------------+--------+
+| employee_id | name    | department  | salary |
++-------------+---------+-------------+--------+
+| 3           | Bob     | Operations  | 48675  |
+| 90          | Alice   | Sales       | 11096  |
+| 9           | Tatiana | Engineering | 33805  |
++-------------+---------+-------------+--------+
+解释:
+只有前 3 行被显示。
diff --git a/leetcode-cn/problem (Chinese)/最后一个能进入巴士的人 [last-person-to-fit-in-the-bus].html b/leetcode-cn/problem (Chinese)/最后一个能进入巴士的人 [last-person-to-fit-in-the-bus].html new file mode 100644 index 00000000..0b6b3e2e --- /dev/null +++ b/leetcode-cn/problem (Chinese)/最后一个能进入巴士的人 [last-person-to-fit-in-the-bus].html @@ -0,0 +1,61 @@ +

表: Queue

+ +
++-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| person_id   | int     |
+| person_name | varchar |
+| weight      | int     |
+| turn        | int     |
++-------------+---------+
+person_id 是这个表具有唯一值的列。
+该表展示了所有候车乘客的信息。
+表中 person_id 和 turn 列将包含从 1 到 n 的所有数字,其中 n 是表中的行数。
+turn 决定了候车乘客上巴士的顺序,其中 turn=1 表示第一个上巴士,turn=n 表示最后一个上巴士。
+weight 表示候车乘客的体重,以千克为单位。
+
+ +

 

+ +

有一队乘客在等着上巴士。然而,巴士有1000  千克 的重量限制,所以其中一部分乘客可能无法上巴士。

+ +

编写解决方案找出 最后一个 上巴士且不超过重量限制的乘客,并报告 person_name 。题目测试用例确保顺位第一的人可以上巴士且不会超重。

+ +

返回结果格式如下所示。

+ +

 

+ +

示例 1:

+ +
+输入:
+Queue 表
++-----------+-------------+--------+------+
+| person_id | person_name | weight | turn |
++-----------+-------------+--------+------+
+| 5         | Alice       | 250    | 1    |
+| 4         | Bob         | 175    | 5    |
+| 3         | Alex        | 350    | 2    |
+| 6         | John Cena   | 400    | 3    |
+| 1         | Winston     | 500    | 6    |
+| 2         | Marie       | 200    | 4    |
++-----------+-------------+--------+------+
+输出:
++-------------+
+| person_name |
++-------------+
+| John Cena   |
++-------------+
+解释:
+为了简化,Queue 表按 turn 列由小到大排序。
++------+----+-----------+--------+--------------+
+| Turn | ID | Name      | Weight | Total Weight |
++------+----+-----------+--------+--------------+
+| 1    | 5  | Alice     | 250    | 250          |
+| 2    | 3  | Alex      | 350    | 600          |
+| 3    | 6  | John Cena | 400    | 1000         | (最后一个上巴士)
+| 4    | 2  | Marie     | 200    | 1200         | (无法上巴士)
+| 5    | 4  | Bob       | 175    | ___          |
+| 6    | 1  | Winston   | 500    | ___          |
++------+----+-----------+--------+--------------+
diff --git a/leetcode-cn/problem (Chinese)/最小操作次数使数组元素相等 II [minimum-moves-to-equal-array-elements-ii].html b/leetcode-cn/problem (Chinese)/最小操作次数使数组元素相等 II [minimum-moves-to-equal-array-elements-ii].html new file mode 100644 index 00000000..dc53edde --- /dev/null +++ b/leetcode-cn/problem (Chinese)/最小操作次数使数组元素相等 II [minimum-moves-to-equal-array-elements-ii].html @@ -0,0 +1,32 @@ +

给你一个长度为 n 的整数数组 nums ,返回使所有数组元素相等需要的最小操作数。

+ +

在一次操作中,你可以使数组中的一个元素加 1 或者减 1

+ +

 

+ +

示例 1:

+ +
+输入:nums = [1,2,3]
+输出:2
+解释:
+只需要两次操作(每次操作指南使一个元素加 1 或减 1):
+[1,2,3]  =>  [2,2,3]  =>  [2,2,2]
+
+ +

示例 2:

+ +
+输入:nums = [1,10,2,9]
+输出:16
+
+ +

 

+ +

提示:

+ +
    +
  • n == nums.length
  • +
  • 1 <= nums.length <= 105
  • +
  • -109 <= nums[i] <= 109
  • +
diff --git a/leetcode-cn/problem (Chinese)/最小栈 [bao-han-minhan-shu-de-zhan-lcof].html b/leetcode-cn/problem (Chinese)/最小栈 [bao-han-minhan-shu-de-zhan-lcof].html new file mode 100644 index 00000000..acfa1b18 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/最小栈 [bao-han-minhan-shu-de-zhan-lcof].html @@ -0,0 +1,53 @@ +

请你设计一个 最小栈 。它提供 pushpoptop 操作,并能在常数时间内检索到最小元素的栈。

+ +

 

+ +

实现 MinStack 类:

+ +
    +
  • MinStack() 初始化堆栈对象。
  • +
  • void push(int val) 将元素val推入堆栈。
  • +
  • void pop() 删除堆栈顶部的元素。
  • +
  • int top() 获取堆栈顶部的元素。
  • +
  • int getMin() 获取堆栈中的最小元素。
  • +
+ +

 

+ +

示例 1:

+ +
+输入:
+["MinStack","push","push","push","getMin","pop","top","getMin"]
+[[],[-2],[2],[-3],[],[],[],[]]
+
+输出:
+[null,null,null,null,-3,null,2,-2]
+
+解释:
+MinStack minStack = new MinStack();
+minStack.push(-2);
+minStack.push(2);
+minStack.push(-3);
+minStack.getMin();   --> 返回 -3.
+minStack.pop();
+minStack.top();      --> 返回 2.
+minStack.getMin();   --> 返回 -2.
+
+ +

 

+ +

 
+提示:

+ +
    +
  • -231 <= val <= 231 - 1
  • +
  • poptopgetMin 操作总是在 非空栈 上调用
  • +
  • pushpoptopgetMin 最多被调用 3 * 104
  • +
+ +

 

+ +

注意:本题与主站 155 题相同:https://leetcode-cn.com/problems/min-stack/

+ +

 

diff --git a/leetcode-cn/problem (Chinese)/望远镜中最高的海拔 [hua-dong-chuang-kou-de-zui-da-zhi-lcof].html b/leetcode-cn/problem (Chinese)/望远镜中最高的海拔 [hua-dong-chuang-kou-de-zui-da-zhi-lcof].html new file mode 100644 index 00000000..cb47643e --- /dev/null +++ b/leetcode-cn/problem (Chinese)/望远镜中最高的海拔 [hua-dong-chuang-kou-de-zui-da-zhi-lcof].html @@ -0,0 +1,30 @@ +

科技馆内有一台虚拟观景望远镜,它可以用来观测特定纬度地区的地形情况。该纬度的海拔数据记于数组 heights ,其中 heights[i] 表示对应位置的海拔高度。请找出并返回望远镜视野范围 limit 内,可以观测到的最高海拔值。

+ +

示例 1:

+ +
+输入:heights = [14,2,27,-5,28,13,39], limit = 3
+输出:[27,27,28,28,39]
+解释:
+  滑动窗口的位置                最大值
+---------------               -----
+[14 2 27] -5 28 13 39          27
+14 [2 27 -5] 28 13 39          27
+14 2 [27 -5 28] 13 39          28
+14 2 27 [-5 28 13] 39          28
+14 2 27 -5 [28 13 39]          39
+ +

 

+ +

提示:

+ +

你可以假设输入总是有效的,在输入数组不为空的情况下:

+ +
    +
  • 1 <= limit <= heights.length
  • +
  • -10000 <= heights[i] <= 10000
  • +
+ +

注意:本题与主站 239 题相同:https://leetcode-cn.com/problems/sliding-window-maximum/

+ +

 

diff --git a/leetcode-cn/problem (Chinese)/查找总价格为目标值的两个商品 [he-wei-sde-liang-ge-shu-zi-lcof].html b/leetcode-cn/problem (Chinese)/查找总价格为目标值的两个商品 [he-wei-sde-liang-ge-shu-zi-lcof].html new file mode 100644 index 00000000..3aec224b --- /dev/null +++ b/leetcode-cn/problem (Chinese)/查找总价格为目标值的两个商品 [he-wei-sde-liang-ge-shu-zi-lcof].html @@ -0,0 +1,25 @@ +

购物车内的商品价格按照升序记录于数组 price。请在购物车中找到两个商品的价格总和刚好是 target。若存在多种情况,返回任一结果即可。

+ +

示例 1:

+ +
+输入:price = [3, 9, 12, 15], target = 18
+输出:[3,15] 或者 [15,3]
+
+ +

示例 2:

+ +
+输入:price = [8, 21, 27, 34, 52, 66], target = 61
+输出:[27,34] 或者 [34,27]
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= price.length <= 10^5
  • +
  • 1 <= price[i] <= 10^6
  • +
  • 1 <= target <= 2*10^6
  • +
diff --git a/leetcode-cn/problem (Chinese)/查找拥有有效邮箱的用户 [find-users-with-valid-e-mails].html b/leetcode-cn/problem (Chinese)/查找拥有有效邮箱的用户 [find-users-with-valid-e-mails].html new file mode 100644 index 00000000..e468b931 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/查找拥有有效邮箱的用户 [find-users-with-valid-e-mails].html @@ -0,0 +1,61 @@ +

表: Users

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| user_id       | int     |
+| name          | varchar |
+| mail          | varchar |
++---------------+---------+
+user_id 是该表的主键(具有唯一值的列)。
+该表包含了网站已注册用户的信息。有一些电子邮件是无效的。
+
+ +

 

+ +

编写一个解决方案,以查找具有有效电子邮件的用户。

+ +

一个有效的电子邮件具有前缀名称和域,其中:

+ +
    +
  1.  前缀 名称是一个字符串,可以包含字母(大写或小写),数字,下划线 '_' ,点 '.' 和/或破折号 '-' 。前缀名称 必须 以字母开头。
  2. +
  3. '@leetcode.com'
  4. +
+ +

以任何顺序返回结果表。

+ +

结果的格式如以下示例所示:

+ +

 

+ +

示例 1:

+ +
+输入:
+Users 表:
++---------+-----------+-------------------------+
+| user_id | name      | mail                    |
++---------+-----------+-------------------------+
+| 1       | Winston   | winston@leetcode.com    |
+| 2       | Jonathan  | jonathanisgreat         |
+| 3       | Annabelle | bella-@leetcode.com     |
+| 4       | Sally     | sally.come@leetcode.com |
+| 5       | Marwan    | quarz#2020@leetcode.com |
+| 6       | David     | david69@gmail.com       |
+| 7       | Shapiro   | .shapo@leetcode.com     |
++---------+-----------+-------------------------+
+输出:
++---------+-----------+-------------------------+
+| user_id | name      | mail                    |
++---------+-----------+-------------------------+
+| 1       | Winston   | winston@leetcode.com    |
+| 3       | Annabelle | bella-@leetcode.com     |
+| 4       | Sally     | sally.come@leetcode.com |
++---------+-----------+-------------------------+
+解释:
+用户 2 的电子邮件没有域。 
+用户 5 的电子邮件带有不允许的 '#' 符号。
+用户 6 的电子邮件没有 leetcode 域。 
+用户 7 的电子邮件以点开头。
+
diff --git a/leetcode-cn/problem (Chinese)/查找集群内的关键连接 [critical-connections-in-a-network].html b/leetcode-cn/problem (Chinese)/查找集群内的关键连接 [critical-connections-in-a-network].html new file mode 100644 index 00000000..39481303 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/查找集群内的关键连接 [critical-connections-in-a-network].html @@ -0,0 +1,35 @@ +

力扣数据中心有 n 台服务器,分别按从 0 到 n-1 的方式进行了编号。它们之间以 服务器到服务器 的形式相互连接组成了一个内部集群,连接是无向的。用  connections 表示集群网络,connections[i] = [a, b] 表示服务器 a 和 b 之间形成连接。任何服务器都可以直接或者间接地通过网络到达任何其他服务器。

+ +

关键连接 是在该集群中的重要连接,假如我们将它移除,便会导致某些服务器无法访问其他服务器。

+ +

请你以任意顺序返回该集群内的所有 关键连接

+ +

 

+ +

示例 1:

+ +

+ +
+输入:n = 4, connections = [[0,1],[1,2],[2,0],[1,3]]
+输出:[[1,3]]
+解释:[[3,1]] 也是正确的。
+ +

示例 2:

+ +
+输入:n = 2, connections = [[0,1]]
+输出:[[0,1]]
+
+ +

 

+ +

提示:

+ +
    +
  • 2 <= n <= 105
  • +
  • n - 1 <= connections.length <= 105
  • +
  • 0 <= ai, bi <= n - 1
  • +
  • ai != bi
  • +
  • 不存在重复的连接
  • +
diff --git a/leetcode-cn/problem (Chinese)/查询结果的质量和占比 [queries-quality-and-percentage].html b/leetcode-cn/problem (Chinese)/查询结果的质量和占比 [queries-quality-and-percentage].html new file mode 100644 index 00000000..e379c71b --- /dev/null +++ b/leetcode-cn/problem (Chinese)/查询结果的质量和占比 [queries-quality-and-percentage].html @@ -0,0 +1,70 @@ +

Queries 表: 

+ +
++-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| query_name  | varchar |
+| result      | varchar |
+| position    | int     |
+| rating      | int     |
++-------------+---------+
+此表可能有重复的行。
+此表包含了一些从数据库中收集的查询信息。
+“位置”(position)列的值为 1500 。
+“评分”(rating)列的值为 15 。评分小于 3 的查询被定义为质量很差的查询。
+
+ +

 

+ +

将查询结果的质量 quality 定义为:

+ +
+

各查询结果的评分与其位置之间比率的平均值。

+
+ +

将劣质查询百分比 poor_query_percentage 为:

+ +
+

评分小于 3 的查询结果占全部查询结果的百分比。

+
+ +

编写解决方案,找出每次的 query_name 、 quality 和 poor_query_percentage

+ +

quality 和 poor_query_percentage 都应 四舍五入到小数点后两位

+ +

任意顺序 返回结果表。

+ +

结果格式如下所示:

+ +

 

+ +

示例 1:

+ +
+输入:
+Queries table:
++------------+-------------------+----------+--------+
+| query_name | result            | position | rating |
++------------+-------------------+----------+--------+
+| Dog        | Golden Retriever  | 1        | 5      |
+| Dog        | German Shepherd   | 2        | 5      |
+| Dog        | Mule              | 200      | 1      |
+| Cat        | Shirazi           | 5        | 2      |
+| Cat        | Siamese           | 3        | 3      |
+| Cat        | Sphynx            | 7        | 4      |
++------------+-------------------+----------+--------+
+输出:
++------------+---------+-----------------------+
+| query_name | quality | poor_query_percentage |
++------------+---------+-----------------------+
+| Dog        | 2.50    | 33.33                 |
+| Cat        | 0.66    | 33.33                 |
++------------+---------+-----------------------+
+解释:
+Dog 查询结果的质量为 ((5 / 1) + (5 / 2) + (1 / 200)) / 3 = 2.50
+Dog 查询结果的劣质查询百分比为 (1 / 3) * 100 = 33.33
+
+Cat 查询结果的质量为 ((2 / 5) + (3 / 3) + (4 / 7)) / 3 = 0.66
+Cat 查询结果的劣质查询百分比为 (1 / 3) * 100 = 33.33
+
diff --git a/leetcode-cn/problem (Chinese)/模糊搜索验证 [zheng-ze-biao-da-shi-pi-pei-lcof].html b/leetcode-cn/problem (Chinese)/模糊搜索验证 [zheng-ze-biao-da-shi-pi-pei-lcof].html new file mode 100644 index 00000000..a2be71de --- /dev/null +++ b/leetcode-cn/problem (Chinese)/模糊搜索验证 [zheng-ze-biao-da-shi-pi-pei-lcof].html @@ -0,0 +1,54 @@ +

请设计一个程序来支持用户在文本编辑器中的模糊搜索功能。用户输入内容中可能使用到如下两种通配符:

+ +
    +
  • '.' 匹配任意单个字符。
  • +
  • '*' 匹配零个或多个前面的那一个元素。
  • +
+ +

 

+ +

请返回用户输入内容 input 所有字符是否可以匹配原文字符串 article

+ +

 

+ +

示例 1:

+ +
+输入: article = "aa", input = "a"
+输出: false
+解释: "a" 无法匹配 "aa" 整个字符串。
+
+ +

示例 2:

+ +
+输入: article = "aa", input = "a*"
+输出: true
+解释: 因为 '*' 代表可以匹配零个或多个前面的那一个元素, 在这里前面的元素就是 'a'。因此,字符串 "aa" 可被视为 'a' 重复了一次。
+
+ +

示例 3:

+ +
+输入: article = "ab", input = ".*"
+输出: true
+解释: ".*" 表示可匹配零个或多个('*')任意字符('.')。
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= article.length <= 20
  • +
  • 1 <= input.length <= 20
  • +
  • article 只包含从 a-z 的小写字母。
  • +
  • input 只包含从 a-z 的小写字母,以及字符 .*
  • +
  • 保证每次出现字符 * 时,前面都匹配到有效的字符
  • +
+ +

 

+ +

注意:本题与主站 10 题相同:https://leetcode-cn.com/problems/regular-expression-matching/

+ +

 

diff --git a/leetcode-cn/problem (Chinese)/每位教师所教授的科目种类的数量 [number-of-unique-subjects-taught-by-each-teacher].html b/leetcode-cn/problem (Chinese)/每位教师所教授的科目种类的数量 [number-of-unique-subjects-taught-by-each-teacher].html new file mode 100644 index 00000000..c295dffe --- /dev/null +++ b/leetcode-cn/problem (Chinese)/每位教师所教授的科目种类的数量 [number-of-unique-subjects-taught-by-each-teacher].html @@ -0,0 +1,56 @@ +

表: Teacher

+ +
++-------------+------+
+| Column Name | Type |
++-------------+------+
+| teacher_id  | int  |
+| subject_id  | int  |
+| dept_id     | int  |
++-------------+------+
+在 SQL 中,(subject_id, dept_id) 是该表的主键。
+该表中的每一行都表示带有 teacher_id 的教师在系 dept_id 中教授科目 subject_id。
+
+ +

 

+ +

查询每位老师在大学里教授的科目种类的数量。

+ +

任意顺序 返回结果表。

+ +

查询结果格式示例如下。

+ +

 

+ +

示例 1:

+ +
+输入: 
+Teacher 表:
++------------+------------+---------+
+| teacher_id | subject_id | dept_id |
++------------+------------+---------+
+| 1          | 2          | 3       |
+| 1          | 2          | 4       |
+| 1          | 3          | 3       |
+| 2          | 1          | 1       |
+| 2          | 2          | 1       |
+| 2          | 3          | 1       |
+| 2          | 4          | 1       |
++------------+------------+---------+
+输出:  
++------------+-----+
+| teacher_id | cnt |
++------------+-----+
+| 1          | 2   |
+| 2          | 4   |
++------------+-----+
+解释: 
+教师 1:
+  - 他在 3、4 系教科目 2。
+  - 他在 3 系教科目 3。
+教师 2:
+  - 他在 1 系教科目 1。
+  - 他在 1 系教科目 2。
+  - 他在 1 系教科目 3。
+  - 他在 1 系教科目 4。
diff --git a/leetcode-cn/problem (Chinese)/每位经理的下属员工数量 [the-number-of-employees-which-report-to-each-employee].html b/leetcode-cn/problem (Chinese)/每位经理的下属员工数量 [the-number-of-employees-which-report-to-each-employee].html new file mode 100644 index 00000000..1cd8ae27 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/每位经理的下属员工数量 [the-number-of-employees-which-report-to-each-employee].html @@ -0,0 +1,44 @@ +

Table: Employees

+ +
+-------------+----------+
+| Column Name | Type     |
++-------------+----------+
+| employee_id | int      |
+| name        | varchar  |
+| reports_to  | int      |
+| age         | int      |
++-------------+----------+
+employee_id 是这个表的主键.
+该表包含员工以及需要听取他们汇报的上级经理的ID的信息。 有些员工不需要向任何人汇报(reports_to 为空)。
+
+ +

 

+ +

对于此问题,我们将至少有一个其他员工需要向他汇报的员工,视为一个经理。

+ +

编写SQL查询需要听取汇报的所有经理的ID、名称、直接向该经理汇报的员工人数,以及这些员工的平均年龄,其中该平均年龄需要四舍五入到最接近的整数。

+ +

返回的结果集需要按照 employee_id 进行排序。

+ +

查询结果的格式如下:

+ +

 

+ +
Employees table:
++-------------+---------+------------+-----+
+| employee_id | name    | reports_to | age |
++-------------+---------+------------+-----+
+| 9           | Hercy   | null       | 43  |
+| 6           | Alice   | 9          | 41  |
+| 4           | Bob     | 9          | 36  |
+| 2           | Winston | null       | 37  |
++-------------+---------+------------+-----+
+
+Result table:
++-------------+-------+---------------+-------------+
+| employee_id | name  | reports_count | average_age |
++-------------+-------+---------------+-------------+
+| 9           | Hercy | 2             | 39          |
++-------------+-------+---------------+-------------+
+Hercy 有两个需要向他汇报的员工, 他们是 Alice and Bob. 他们的平均年龄是 (41+36)/2 = 38.5, 四舍五入的结果是 39.
+
diff --git a/leetcode-cn/problem (Chinese)/每台机器的进程平均运行时间 [average-time-of-process-per-machine].html b/leetcode-cn/problem (Chinese)/每台机器的进程平均运行时间 [average-time-of-process-per-machine].html new file mode 100644 index 00000000..4feaa4e2 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/每台机器的进程平均运行时间 [average-time-of-process-per-machine].html @@ -0,0 +1,68 @@ +

表: Activity

+ +
++----------------+---------+
+| Column Name    | Type    |
++----------------+---------+
+| machine_id     | int     |
+| process_id     | int     |
+| activity_type  | enum    |
+| timestamp      | float   |
++----------------+---------+
+该表展示了一家工厂网站的用户活动。
+(machine_id, process_id, activity_type) 是当前表的主键(具有唯一值的列的组合)。
+machine_id 是一台机器的ID号。
+process_id 是运行在各机器上的进程ID号。
+activity_type 是枚举类型 ('start', 'end')。
+timestamp 是浮点类型,代表当前时间(以秒为单位)。
+'start' 代表该进程在这台机器上的开始运行时间戳 , 'end' 代表该进程在这台机器上的终止运行时间戳。
+同一台机器,同一个进程都有一对开始时间戳和结束时间戳,而且开始时间戳永远在结束时间戳前面。
+ +

 

+ +

现在有一个工厂网站由几台机器运行,每台机器上运行着 相同数量的进程 。编写解决方案,计算每台机器各自完成一个进程任务的平均耗时。

+ +

完成一个进程任务的时间指进程的'end' 时间戳 减去 'start' 时间戳。平均耗时通过计算每台机器上所有进程任务的总耗费时间除以机器上的总进程数量获得。

+ +

结果表必须包含machine_id(机器ID) 和对应的 average time(平均耗时) 别名 processing_time,且四舍五入保留3位小数。

+ +

任意顺序 返回表。

+ +

具体参考例子如下。

+ +

 

+ +

示例 1:

+ +
+输入:
+Activity table:
++------------+------------+---------------+-----------+
+| machine_id | process_id | activity_type | timestamp |
++------------+------------+---------------+-----------+
+| 0          | 0          | start         | 0.712     |
+| 0          | 0          | end           | 1.520     |
+| 0          | 1          | start         | 3.140     |
+| 0          | 1          | end           | 4.120     |
+| 1          | 0          | start         | 0.550     |
+| 1          | 0          | end           | 1.550     |
+| 1          | 1          | start         | 0.430     |
+| 1          | 1          | end           | 1.420     |
+| 2          | 0          | start         | 4.100     |
+| 2          | 0          | end           | 4.512     |
+| 2          | 1          | start         | 2.500     |
+| 2          | 1          | end           | 5.000     |
++------------+------------+---------------+-----------+
+输出:
++------------+-----------------+
+| machine_id | processing_time |
++------------+-----------------+
+| 0          | 0.894           |
+| 1          | 0.995           |
+| 2          | 1.456           |
++------------+-----------------+
+解释:
+一共有3台机器,每台机器运行着两个进程.
+机器 0 的平均耗时: ((1.520 - 0.712) + (4.120 - 3.140)) / 2 = 0.894
+机器 1 的平均耗时: ((1.550 - 0.550) + (1.420 - 0.430)) / 2 = 0.995
+机器 2 的平均耗时: ((4.512 - 4.100) + (5.000 - 2.500)) / 2 = 1.456
diff --git a/leetcode-cn/problem (Chinese)/每月交易 I [monthly-transactions-i].html b/leetcode-cn/problem (Chinese)/每月交易 I [monthly-transactions-i].html new file mode 100644 index 00000000..c6fdd00d --- /dev/null +++ b/leetcode-cn/problem (Chinese)/每月交易 I [monthly-transactions-i].html @@ -0,0 +1,48 @@ +

表:Transactions

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| id            | int     |
+| country       | varchar |
+| state         | enum    |
+| amount        | int     |
+| trans_date    | date    |
++---------------+---------+
+id 是这个表的主键。
+该表包含有关传入事务的信息。
+state 列类型为 ["approved", "declined"] 之一。
+
+ +

 

+ +

编写一个 sql 查询来查找每个月和每个国家/地区的事务数及其总金额、已批准的事务数及其总金额。

+ +

任意顺序 返回结果表。

+ +

查询结果格式如下所示。

+ +

 

+ +

示例 1:

+ +
+输入:
+Transactions table:
++------+---------+----------+--------+------------+
+| id   | country | state    | amount | trans_date |
++------+---------+----------+--------+------------+
+| 121  | US      | approved | 1000   | 2018-12-18 |
+| 122  | US      | declined | 2000   | 2018-12-19 |
+| 123  | US      | approved | 2000   | 2019-01-01 |
+| 124  | DE      | approved | 2000   | 2019-01-07 |
++------+---------+----------+--------+------------+
+输出:
++----------+---------+-------------+----------------+--------------------+-----------------------+
+| month    | country | trans_count | approved_count | trans_total_amount | approved_total_amount |
++----------+---------+-------------+----------------+--------------------+-----------------------+
+| 2018-12  | US      | 2           | 1              | 3000               | 1000                  |
+| 2019-01  | US      | 1           | 1              | 2000               | 2000                  |
+| 2019-01  | DE      | 1           | 1              | 2000               | 2000                  |
++----------+---------+-------------+----------------+--------------------+-----------------------+
diff --git a/leetcode-cn/problem (Chinese)/游戏玩法分析 IV [game-play-analysis-iv].html b/leetcode-cn/problem (Chinese)/游戏玩法分析 IV [game-play-analysis-iv].html new file mode 100644 index 00000000..93611d7a --- /dev/null +++ b/leetcode-cn/problem (Chinese)/游戏玩法分析 IV [game-play-analysis-iv].html @@ -0,0 +1,47 @@ +

Table: Activity

+ +
++--------------+---------+
+| Column Name  | Type    |
++--------------+---------+
+| player_id    | int     |
+| device_id    | int     |
+| event_date   | date    |
+| games_played | int     |
++--------------+---------+
+(player_id,event_date)是此表的主键(具有唯一值的列的组合)。
+这张表显示了某些游戏的玩家的活动情况。
+每一行是一个玩家的记录,他在某一天使用某个设备注销之前登录并玩了很多游戏(可能是 0)。
+
+ +

 

+ +

编写解决方案,报告在首次登录的第二天再次登录的玩家的 比率四舍五入到小数点后两位。换句话说,你需要计算从首次登录日期开始至少连续两天登录的玩家的数量,然后除以玩家总数。

+ +

结果格式如下所示:

+ +

 

+ +

示例 1:

+ +
+输入:
+Activity table:
++-----------+-----------+------------+--------------+
+| player_id | device_id | event_date | games_played |
++-----------+-----------+------------+--------------+
+| 1         | 2         | 2016-03-01 | 5            |
+| 1         | 2         | 2016-03-02 | 6            |
+| 2         | 3         | 2017-06-25 | 1            |
+| 3         | 1         | 2016-03-02 | 0            |
+| 3         | 4         | 2018-07-03 | 5            |
++-----------+-----------+------------+--------------+
+输出:
++-----------+
+| fraction  |
++-----------+
+| 0.33      |
++-----------+
+解释:
+只有 ID 为 1 的玩家在第一天登录后才重新登录,所以答案是 1/3 = 0.33
+
diff --git a/leetcode-cn/problem (Chinese)/点名 [que-shi-de-shu-zi-lcof].html b/leetcode-cn/problem (Chinese)/点名 [que-shi-de-shu-zi-lcof].html new file mode 100644 index 00000000..d27a69ca --- /dev/null +++ b/leetcode-cn/problem (Chinese)/点名 [que-shi-de-shu-zi-lcof].html @@ -0,0 +1,22 @@ +

某班级 n 位同学的学号为 0 ~ n-1。点名结果记录于升序数组 records。假定仅有一位同学缺席,请返回他的学号。

+ +

 

+ +

示例 1:

+ +
+输入: records = [0,1,2,3,5]
+输出: 4
+
+ +

示例 2:

+ +
+输入: records = [0, 1, 2, 3, 4, 5, 6, 8]
+输出: 7
+ +

 

+ +

提示:

+ +

1 <= records.length <= 10000

diff --git a/leetcode-cn/problem (Chinese)/爱吃香蕉的狒狒 [nZZqjQ].html b/leetcode-cn/problem (Chinese)/爱吃香蕉的狒狒 [nZZqjQ].html new file mode 100644 index 00000000..ed31100f --- /dev/null +++ b/leetcode-cn/problem (Chinese)/爱吃香蕉的狒狒 [nZZqjQ].html @@ -0,0 +1,47 @@ +

狒狒喜欢吃香蕉。这里有 N 堆香蕉,第 i 堆中有 piles[i] 根香蕉。警卫已经离开了,将在 H 小时后回来。

+ +

狒狒可以决定她吃香蕉的速度 K (单位:根/小时)。每个小时,她将会选择一堆香蕉,从中吃掉 K 根。如果这堆香蕉少于 K 根,她将吃掉这堆的所有香蕉,然后这一小时内不会再吃更多的香蕉,下一个小时才会开始吃另一堆的香蕉。  

+ +

狒狒喜欢慢慢吃,但仍然想在警卫回来前吃掉所有的香蕉。

+ +

返回她可以在 H 小时内吃掉所有香蕉的最小速度 KK 为整数)。

+ +

 

+ +
    +
+ +

示例 1:

+ +
+输入: piles = [3,6,7,11], H = 8
+输出: 4
+
+ +

示例 2:

+ +
+输入: piles = [30,11,23,4,20], H = 5
+输出: 30
+
+ +

示例 3:

+ +
+输入: piles = [30,11,23,4,20], H = 6
+输出: 23
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= piles.length <= 10^4
  • +
  • piles.length <= H <= 10^9
  • +
  • 1 <= piles[i] <= 10^9
  • +
+ +

 

+ +

注意:本题与主站 875 题相同: https://leetcode-cn.com/problems/koko-eating-bananas/

diff --git a/leetcode-cn/problem (Chinese)/珠宝的最高价值 [li-wu-de-zui-da-jie-zhi-lcof].html b/leetcode-cn/problem (Chinese)/珠宝的最高价值 [li-wu-de-zui-da-jie-zhi-lcof].html new file mode 100644 index 00000000..e0fd76f9 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/珠宝的最高价值 [li-wu-de-zui-da-jie-zhi-lcof].html @@ -0,0 +1,29 @@ +

现有一个记作二维矩阵 frame 的珠宝架,其中 frame[i][j] 为该位置珠宝的价值。拿取珠宝的规则为:

+ +
    +
  • 只能从架子的左上角开始拿珠宝
  • +
  • 每次可以移动到右侧或下侧的相邻位置
  • +
  • 到达珠宝架子的右下角时,停止拿取
  • +
+ +

注意:珠宝的价值都是大于 0 的。除非这个架子上没有任何珠宝,比如 frame = [[0]]

+ +

 

+ +

示例 1:

+ +
+输入: frame = [[1,3,1],[1,5,1],[4,2,1]]
+输出: 12
+解释: 路径 1→3→5→2→1 可以拿到最高价值的珠宝
+ +

 

+ +

提示:

+ +
    +
  • 0 < frame.length <= 200
  • +
  • 0 < frame[0].length <= 200
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/电影评分 [movie-rating].html b/leetcode-cn/problem (Chinese)/电影评分 [movie-rating].html new file mode 100644 index 00000000..40f39995 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/电影评分 [movie-rating].html @@ -0,0 +1,103 @@ +

表:Movies

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| movie_id      | int     |
+| title         | varchar |
++---------------+---------+
+movie_id 是这个表的主键(具有唯一值的列)。
+title 是电影的名字。
+
+ +

表:Users

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| user_id       | int     |
+| name          | varchar |
++---------------+---------+
+user_id 是表的主键(具有唯一值的列)。
+
+ +

表:MovieRating

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| movie_id      | int     |
+| user_id       | int     |
+| rating        | int     |
+| created_at    | date    |
++---------------+---------+
+(movie_id, user_id) 是这个表的主键(具有唯一值的列的组合)。
+这个表包含用户在其评论中对电影的评分 rating 。
+created_at 是用户的点评日期。 
+
+ +

 

+ +

请你编写一个解决方案:

+ +
    +
  • 查找评论电影数量最多的用户名。如果出现平局,返回字典序较小的用户名。
  • +
  • 查找在 February 2020 平均评分最高 的电影名称。如果出现平局,返回字典序较小的电影名称。
  • +
+ +

字典序 ,即按字母在字典中出现顺序对字符串排序,字典序较小则意味着排序靠前。

+ +

返回结果格式如下例所示。

+ +

 

+ +

示例 1:

+ +
+输入:
+Movies 表:
++-------------+--------------+
+| movie_id    |  title       |
++-------------+--------------+
+| 1           | Avengers     |
+| 2           | Frozen 2     |
+| 3           | Joker        |
++-------------+--------------+
+Users 表:
++-------------+--------------+
+| user_id     |  name        |
++-------------+--------------+
+| 1           | Daniel       |
+| 2           | Monica       |
+| 3           | Maria        |
+| 4           | James        |
++-------------+--------------+
+MovieRating 表:
++-------------+--------------+--------------+-------------+
+| movie_id    | user_id      | rating       | created_at  |
++-------------+--------------+--------------+-------------+
+| 1           | 1            | 3            | 2020-01-12  |
+| 1           | 2            | 4            | 2020-02-11  |
+| 1           | 3            | 2            | 2020-02-12  |
+| 1           | 4            | 1            | 2020-01-01  |
+| 2           | 1            | 5            | 2020-02-17  | 
+| 2           | 2            | 2            | 2020-02-01  | 
+| 2           | 3            | 2            | 2020-03-01  |
+| 3           | 1            | 3            | 2020-02-22  | 
+| 3           | 2            | 4            | 2020-02-25  | 
++-------------+--------------+--------------+-------------+
+输出:
+Result 表:
++--------------+
+| results      |
++--------------+
+| Daniel       |
+| Frozen 2     |
++--------------+
+解释:
+Daniel 和 Monica 都点评了 3 部电影("Avengers", "Frozen 2" 和 "Joker") 但是 Daniel 字典序比较小。
+Frozen 2 和 Joker 在 2 月的评分都是 3.5,但是 Frozen 2 的字典序比较小。
+
diff --git a/leetcode-cn/problem (Chinese)/砍竹子 I [jian-sheng-zi-lcof].html b/leetcode-cn/problem (Chinese)/砍竹子 I [jian-sheng-zi-lcof].html new file mode 100644 index 00000000..1a6dc407 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/砍竹子 I [jian-sheng-zi-lcof].html @@ -0,0 +1,17 @@ +

现需要将一根长为正整数 bamboo_len 的竹子砍为若干段,每段长度均为正整数。请返回每段竹子长度的最大乘积是多少。

+ +

 

+ +

示例 1:

+ +
+输入: bamboo_len = 12
+输出: 81
+
+提示: + +
    +
  • 2 <= bamboo_len <= 58
  • +
+ +

注意:本题与主站 343 题相同:https://leetcode-cn.com/problems/integer-break/

diff --git a/leetcode-cn/problem (Chinese)/砍竹子 II [jian-sheng-zi-ii-lcof].html b/leetcode-cn/problem (Chinese)/砍竹子 II [jian-sheng-zi-ii-lcof].html new file mode 100644 index 00000000..b3fa2ec4 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/砍竹子 II [jian-sheng-zi-ii-lcof].html @@ -0,0 +1,24 @@ +

现需要将一根长为正整数 bamboo_len 的竹子砍为若干段,每段长度均为 正整数。请返回每段竹子长度的 最大乘积 是多少。

+ +

答案需要取模 1e9+7(1000000007),如计算初始结果为:1000000008,请返回 1。

+ +

 

+ +

示例 1:

+ +
+输入:bamboo_len = 12
+输出:81
+
+ +

 

+ +

提示:

+ +
    +
  • 2 <= bamboo_len <= 1000
  • +
+ +

注意:本题与主站 343 题相同:https://leetcode-cn.com/problems/integer-break/

+ +

 

diff --git a/leetcode-cn/problem (Chinese)/破冰游戏 [yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof].html b/leetcode-cn/problem (Chinese)/破冰游戏 [yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof].html new file mode 100644 index 00000000..2e098ea7 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/破冰游戏 [yuan-quan-zhong-zui-hou-sheng-xia-de-shu-zi-lcof].html @@ -0,0 +1,28 @@ +

社团共有 num 为成员参与破冰游戏,编号为 0 ~ num-1。成员们按照编号顺序围绕圆桌而坐。社长抽取一个数字 target,从 0 号成员起开始计数,排在第 target 位的成员离开圆桌,且成员离开后从下一个成员开始计数。请返回游戏结束时最后一位成员的编号。

+ +

 

+ +

示例 1:

+ +
+输入:num = 7, target = 4
+输出:1
+
+ +

示例 2:

+ +
+输入:num = 12, target = 5
+输出:0
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= num <= 10^5
  • +
  • 1 <= target <= 10^6
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/破解闯关密码 [ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof].html b/leetcode-cn/problem (Chinese)/破解闯关密码 [ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof].html new file mode 100644 index 00000000..eb91a27a --- /dev/null +++ b/leetcode-cn/problem (Chinese)/破解闯关密码 [ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof].html @@ -0,0 +1,39 @@ +

闯关游戏需要破解一组密码,闯关组给出的有关密码的线索是:

+ +
    +
  • 一个拥有密码所有元素的非负整数数组 password
  • +
  • 密码是 password 中所有元素拼接后得到的最小的一个数
  • +
+ +

请编写一个程序返回这个密码。

+ +

 

+ +

示例 1:

+ +
+输入: password = [15, 8, 7]
+输出: "1578"
+ +

示例 2:

+ +
+输入: password = [0, 3, 30, 34, 5, 9]
+输出: "03033459"
+ +

 

+ +

提示:

+ +
    +
  • 0 < password.length <= 100
  • +
+ +

说明:

+ +
    +
  • 输出结果可能非常大,所以你需要返回一个字符串而不是整数
  • +
  • 拼接起来的数字可能会有前导 0,最后结果不需要去掉前导 0
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/确认率 [confirmation-rate].html b/leetcode-cn/problem (Chinese)/确认率 [confirmation-rate].html new file mode 100644 index 00000000..b7f8fb3c --- /dev/null +++ b/leetcode-cn/problem (Chinese)/确认率 [confirmation-rate].html @@ -0,0 +1,80 @@ +

表: Signups

+ +
++----------------+----------+
+| Column Name    | Type     |
++----------------+----------+
+| user_id        | int      |
+| time_stamp     | datetime |
++----------------+----------+
+User_id是该表的主键。
+每一行都包含ID为user_id的用户的注册时间信息。
+
+ +

 

+ +

表: Confirmations

+ +
++----------------+----------+
+| Column Name    | Type     |
++----------------+----------+
+| user_id        | int      |
+| time_stamp     | datetime |
+| action         | ENUM     |
++----------------+----------+
+(user_id, time_stamp)是该表的主键。
+user_id是一个引用到注册表的外键。
+action是类型为('confirmed', 'timeout')的ENUM
+该表的每一行都表示ID为user_id的用户在time_stamp请求了一条确认消息,该确认消息要么被确认('confirmed'),要么被过期('timeout')。
+
+ +

 

+ +

用户的 确认率 是 'confirmed' 消息的数量除以请求的确认消息的总数。没有请求任何确认消息的用户的确认率为 0 。确认率四舍五入到 小数点后两位

+ +

编写一个SQL查询来查找每个用户的 确认率 。
+
+以 任意顺序 返回结果表。
+
+查询结果格式如下所示。
+
+示例1:

+ +
+输入:
+Signups 表:
++---------+---------------------+
+| user_id | time_stamp          |
++---------+---------------------+
+| 3       | 2020-03-21 10:16:13 |
+| 7       | 2020-01-04 13:57:59 |
+| 2       | 2020-07-29 23:09:44 |
+| 6       | 2020-12-09 10:39:37 |
++---------+---------------------+
+Confirmations 表:
++---------+---------------------+-----------+
+| user_id | time_stamp          | action    |
++---------+---------------------+-----------+
+| 3       | 2021-01-06 03:30:46 | timeout   |
+| 3       | 2021-07-14 14:00:00 | timeout   |
+| 7       | 2021-06-12 11:57:29 | confirmed |
+| 7       | 2021-06-13 12:58:28 | confirmed |
+| 7       | 2021-06-14 13:59:27 | confirmed |
+| 2       | 2021-01-22 00:00:00 | confirmed |
+| 2       | 2021-02-28 23:59:59 | timeout   |
++---------+---------------------+-----------+
+输出: 
++---------+-------------------+
+| user_id | confirmation_rate |
++---------+-------------------+
+| 6       | 0.00              |
+| 3       | 0.00              |
+| 7       | 1.00              |
+| 2       | 0.50              |
++---------+-------------------+
+解释:
+用户 6 没有请求任何确认消息。确认率为 0。
+用户 3 进行了 2 次请求,都超时了。确认率为 0。
+用户 7 提出了 3 个请求,所有请求都得到了确认。确认率为 1。
+用户 2 做了 2 个请求,其中一个被确认,另一个超时。确认率为 1 / 2 = 0.5。
diff --git a/leetcode-cn/problem (Chinese)/统计目标成绩的出现次数 [zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof].html b/leetcode-cn/problem (Chinese)/统计目标成绩的出现次数 [zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof].html new file mode 100644 index 00000000..db2876bf --- /dev/null +++ b/leetcode-cn/problem (Chinese)/统计目标成绩的出现次数 [zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof].html @@ -0,0 +1,32 @@ +

某班级考试成绩按非严格递增顺序记录于整数数组 scores,请返回目标成绩 target 的出现次数。

+ +

 

+ +

示例 1:

+ +
+输入: scores = [2, 2, 3, 4, 4, 4, 5, 6, 6, 8], target = 4
+输出: 3
+ +

示例 2:

+ +
+输入: scores = [1, 2, 3, 5, 7, 9], target = 6
+输出: 0
+ +

 

+ +

提示:

+ +
    +
  • 0 <= scores.length <= 105
  • +
  • -109 <= scores[i] <= 109
  • +
  • scores 是一个非递减数组
  • +
  • -109 <= target <= 109
  • +
+ +

 

+ +

注意:本题与主站 34 题相同(仅返回值不同):https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/

+ +

 

diff --git a/leetcode-cn/problem (Chinese)/统计结果概率 [nge-tou-zi-de-dian-shu-lcof].html b/leetcode-cn/problem (Chinese)/统计结果概率 [nge-tou-zi-de-dian-shu-lcof].html new file mode 100644 index 00000000..4ee51ef4 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/统计结果概率 [nge-tou-zi-de-dian-shu-lcof].html @@ -0,0 +1,29 @@ +

你选择掷出 num 个色子,请返回所有点数总和的概率。

+ +

你需要用一个浮点数数组返回答案,其中第 i 个元素代表这 num 个骰子所能掷出的点数集合中第 i 小的那个的概率。

+ +

 

+ +

示例 1:

+ +
+输入:num = 3
+输出:[0.00463,0.01389,0.02778,0.04630,0.06944,0.09722,0.11574,0.12500,0.12500,0.11574,0.09722,0.06944,0.04630,0.02778,0.01389,0.00463]
+
+ +

示例 2:

+ +
+输入:num = 5
+输出:[0.00013,0.00064,0.00193,0.00450,0.00900,0.01620,0.02636,0.03922,0.05401,0.06944,0.08372,0.09452,0.10031,0.10031,0.09452,0.08372,0.06944,0.05401,0.03922,0.02636,0.01620,0.00900,0.00450,0.00193,0.00064,0.00013]
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= num <= 11
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/翻转二叉树 [er-cha-shu-de-jing-xiang-lcof].html b/leetcode-cn/problem (Chinese)/翻转二叉树 [er-cha-shu-de-jing-xiang-lcof].html new file mode 100644 index 00000000..4b22ea2b --- /dev/null +++ b/leetcode-cn/problem (Chinese)/翻转二叉树 [er-cha-shu-de-jing-xiang-lcof].html @@ -0,0 +1,27 @@ +

给定一棵二叉树的根节点 root,请左右翻转这棵二叉树,并返回其根节点。

+ +

 

+ +

示例 1:

+ +

+ +
+输入:root = [5,7,9,8,3,2,4]
+输出:[5,9,7,4,2,3,8]
+
+ +

 

+ +

提示:

+ +
    +
  • 树中节点数目范围在 [0, 100]
  • +
  • -100 <= Node.val <= 100
  • +
+ +

 

+ +

注意:本题与主站 226 题相同:https://leetcode-cn.com/problems/invert-binary-tree/

+ +

 

diff --git a/leetcode-cn/problem (Chinese)/至少有5名直接下属的经理 [managers-with-at-least-5-direct-reports].html b/leetcode-cn/problem (Chinese)/至少有5名直接下属的经理 [managers-with-at-least-5-direct-reports].html new file mode 100644 index 00000000..63a5a0df --- /dev/null +++ b/leetcode-cn/problem (Chinese)/至少有5名直接下属的经理 [managers-with-at-least-5-direct-reports].html @@ -0,0 +1,48 @@ +

表: Employee

+ +
++-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| id          | int     |
+| name        | varchar |
+| department  | varchar |
+| managerId   | int     |
++-------------+---------+
+id 是此表的主键(具有唯一值的列)。
+该表的每一行表示雇员的名字、他们的部门和他们的经理的id。
+如果managerId为空,则该员工没有经理。
+没有员工会成为自己的管理者。
+
+ +

 

+ +

编写一个解决方案,找出至少有五个直接下属的经理。

+ +

任意顺序 返回结果表。

+ +

查询结果格式如下所示。

+ +

 

+ +

示例 1:

+ +
+输入: 
+Employee 表:
++-----+-------+------------+-----------+
+| id  | name  | department | managerId |
++-----+-------+------------+-----------+
+| 101 | John  | A          | Null      |
+| 102 | Dan   | A          | 101       |
+| 103 | James | A          | 101       |
+| 104 | Amy   | A          | 101       |
+| 105 | Anne  | A          | 101       |
+| 106 | Ron   | B          | 101       |
++-----+-------+------------+-----------+
+输出: 
++------+
+| name |
++------+
+| John |
++------+
diff --git a/leetcode-cn/problem (Chinese)/获取 DataFrame 的大小 [get-the-size-of-a-dataframe].html b/leetcode-cn/problem (Chinese)/获取 DataFrame 的大小 [get-the-size-of-a-dataframe].html new file mode 100644 index 00000000..348e9479 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/获取 DataFrame 的大小 [get-the-size-of-a-dataframe].html @@ -0,0 +1,46 @@ +
+DataFrame players:
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| player_id   | int    |
+| name        | object |
+| age         | int    |
+| position    | object |
+| ...         | ...    |
++-------------+--------+
+
+ +

编写一个解决方案,计算并显示 players 的 行数和列数

+ +

将结果返回为一个数组:

+ +

[number of rows, number of columns]

+ +

返回结果格式如下示例所示。

+ +

 

+ +

示例 1:

+ +
+输入:
++-----------+----------+-----+-------------+--------------------+
+| player_id | name     | age | position    | team               |
++-----------+----------+-----+-------------+--------------------+
+| 846       | Mason    | 21  | Forward     | RealMadrid         |
+| 749       | Riley    | 30  | Winger      | Barcelona          |
+| 155       | Bob      | 28  | Striker     | ManchesterUnited   |
+| 583       | Isabella | 32  | Goalkeeper  | Liverpool          |
+| 388       | Zachary  | 24  | Midfielder  | BayernMunich       |
+| 883       | Ava      | 23  | Defender    | Chelsea            |
+| 355       | Violet   | 18  | Striker     | Juventus           |
+| 247       | Thomas   | 27  | Striker     | ParisSaint-Germain |
+| 761       | Jack     | 33  | Midfielder  | ManchesterCity     |
+| 642       | Charlie  | 36  | Center-back | Arsenal            |
++-----------+----------+-----+-------------+--------------------+
+输出:
+[10, 5]
+解释:
+这个 DataFrame 包含 10 行和 5 列。
+
diff --git a/leetcode-cn/problem (Chinese)/螺旋遍历二维数组 [shun-shi-zhen-da-yin-ju-zhen-lcof].html b/leetcode-cn/problem (Chinese)/螺旋遍历二维数组 [shun-shi-zhen-da-yin-ju-zhen-lcof].html new file mode 100644 index 00000000..0c9ab893 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/螺旋遍历二维数组 [shun-shi-zhen-da-yin-ju-zhen-lcof].html @@ -0,0 +1,32 @@ +

给定一个二维数组 array,请返回「螺旋遍历」该数组的结果。

+ +

螺旋遍历:从左上角开始,按照 向右向下向左向上 的顺序 依次 提取元素,然后再进入内部一层重复相同的步骤,直到提取完所有元素。

+ +

 

+ +

示例 1:

+ +
+输入:array = [[1,2,3],[8,9,4],[7,6,5]]
+输出:[1,2,3,4,5,6,7,8,9]
+
+ +

示例 2:

+ +
+输入:array  = [[1,2,3,4],[12,13,14,5],[11,16,15,6],[10,9,8,7]]
+输出:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
+
+ +

 

+ +

限制:

+ +
    +
  • 0 <= array.length <= 100
  • +
  • 0 <= array[i].length <= 100
  • +
+ +

注意:本题与主站 54 题相同:https://leetcode-cn.com/problems/spiral-matrix/

+ +

 

diff --git a/leetcode-cn/problem (Chinese)/衣橱整理 [ji-qi-ren-de-yun-dong-fan-wei-lcof].html b/leetcode-cn/problem (Chinese)/衣橱整理 [ji-qi-ren-de-yun-dong-fan-wei-lcof].html new file mode 100644 index 00000000..3f7e00a3 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/衣橱整理 [ji-qi-ren-de-yun-dong-fan-wei-lcof].html @@ -0,0 +1,25 @@ +

家居整理师将待整理衣橱划分为 m x n 的二维矩阵 grid,其中 grid[i][j] 代表一个需要整理的格子。整理师自 grid[0][0] 开始 逐行逐列 地整理每个格子。

+ +

整理规则为:在整理过程中,可以选择 向右移动一格 或 向下移动一格,但不能移动到衣柜之外。同时,不需要整理 digit(i) + digit(j) > cnt 的格子,其中 digit(x) 表示数字 x 的各数位之和。

+ +

请返回整理师 总共需要整理多少个格子

+ +

 

+ +

示例 1:

+ +
+输入:m = 4, n = 7, cnt = 5
+输出:18
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= n, m <= 100
  • +
  • 0 <= cnt <= 20
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/解密数字 [ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof].html b/leetcode-cn/problem (Chinese)/解密数字 [ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof].html new file mode 100644 index 00000000..5bd83ab3 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/解密数字 [ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof].html @@ -0,0 +1,29 @@ +

现有一串神秘的密文 ciphertext,经调查,密文的特点和规则如下:

+ +
    +
  • 密文由非负整数组成
  • +
  • 数字 0-25 分别对应字母 a-z
  • +
+ +

请根据上述规则将密文 ciphertext 解密为字母,并返回共有多少种解密结果。

+ +

 

+ +

 

+ +

示例 1:

+ +
+输入: ciphertext = 216612
+输出: 6
+解释: 216612 解密后有 6 种不同的形式,分别是 "cbggbc","vggbc","vggm","cbggm","cqggbc" 和 "cqggm" 
+ +

 

+ +

提示:

+ +
    +
  • 0 <= ciphertext < 231
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/计算二叉树的深度 [er-cha-shu-de-shen-du-lcof].html b/leetcode-cn/problem (Chinese)/计算二叉树的深度 [er-cha-shu-de-shen-du-lcof].html new file mode 100644 index 00000000..314afd09 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/计算二叉树的深度 [er-cha-shu-de-shen-du-lcof].html @@ -0,0 +1,25 @@ +

某公司架构以二叉树形式记录,请返回该公司的层级数。

+ +

 

+ +

示例 1:

+ +

+ +
+输入:root = [1, 2, 2, 3, null, null, 5, 4, null, null, 4]
+输出: 4
+解释: 上面示例中的二叉树的最大深度是 4,沿着路径 1 -> 2 -> 3 -> 4 或 1 -> 2 -> 5 -> 4 到达叶节点的最长路径上有 4 个节点。
+
+ +

 

+ +

提示:

+ +
    +
  • 节点总数 <= 10000
  • +
+ +

注意:本题与主站 104 题相同:https://leetcode-cn.com/problems/maximum-depth-of-binary-tree/

+ +

 

diff --git a/leetcode-cn/problem (Chinese)/训练计划 I [diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof].html b/leetcode-cn/problem (Chinese)/训练计划 I [diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof].html new file mode 100644 index 00000000..3073fc98 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/训练计划 I [diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof].html @@ -0,0 +1,21 @@ +

教练使用整数数组 actions 记录一系列核心肌群训练项目编号。为增强训练趣味性,需要将所有奇数编号训练项目调整至偶数编号训练项目之前。请将调整后的训练项目编号以 数组 形式返回。

+ +

 

+ +

示例 1:

+ +
+输入:actions = [1,2,3,4,5]
+输出:[1,3,5,2,4] 
+解释:为正确答案之一
+ +

 

+ +

提示:

+ +
    +
  • 0 <= actions.length <= 50000
  • +
  • 0 <= actions[i] <= 10000
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/训练计划 II [lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof].html b/leetcode-cn/problem (Chinese)/训练计划 II [lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof].html new file mode 100644 index 00000000..73f3fd5c --- /dev/null +++ b/leetcode-cn/problem (Chinese)/训练计划 II [lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof].html @@ -0,0 +1,21 @@ +

给定一个头节点为 head 的链表用于记录一系列核心肌群训练项目编号,请查找并返回倒数第 cnt 个训练项目编号。

+ +

 

+ +

示例 1:

+ +
+输入:head = [2,4,7,8], cnt = 1
+输出:8
+ +

 

+ +

提示:

+ +
    +
  • 1 <= head.length <= 100
  • +
  • 0 <= head[i] <= 100
  • +
  • 1 <= cnt <= head.length
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/训练计划 III [fan-zhuan-lian-biao-lcof].html b/leetcode-cn/problem (Chinese)/训练计划 III [fan-zhuan-lian-biao-lcof].html new file mode 100644 index 00000000..850059ce --- /dev/null +++ b/leetcode-cn/problem (Chinese)/训练计划 III [fan-zhuan-lian-biao-lcof].html @@ -0,0 +1,43 @@ +

给定一个头节点为 head 的单链表用于记录一系列核心肌群训练编号,请将该系列训练编号 倒序 记录于链表并返回。

+ +

 

+ +

示例 1:

+ +
+输入:head = [1,2,3,4,5]
+输出:[5,4,3,2,1]
+
+ +

 

+ +

示例 2:

+ +
+输入:head = [1,2]
+输出:[2,1]
+
+ +

 

+ +

示例 3:

+ +
+输入:head = []
+输出:[]
+
+ +

 

+ +

提示:

+ +
    +
  • 链表中节点的数目范围是 [0, 5000]
  • +
  • -5000 <= Node.val <= 5000
  • +
+ +

 

+ +

注意:本题与主站 206 题相同:https://leetcode-cn.com/problems/reverse-linked-list/

+ +

 

diff --git a/leetcode-cn/problem (Chinese)/训练计划 IV [he-bing-liang-ge-pai-xu-de-lian-biao-lcof].html b/leetcode-cn/problem (Chinese)/训练计划 IV [he-bing-liang-ge-pai-xu-de-lian-biao-lcof].html new file mode 100644 index 00000000..1a68fd23 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/训练计划 IV [he-bing-liang-ge-pai-xu-de-lian-biao-lcof].html @@ -0,0 +1,35 @@ +

给定两个以 有序链表 形式记录的训练计划 l1l2,分别记录了两套核心肌群训练项目编号,请合并这两个训练计划,按训练项目编号 升序 记录于链表并返回。

+ +

注意:新链表是通过拼接给定的两个链表的所有节点组成的。

+ +

 

+ +

示例 1:

+ +
+输入:l1 = [1,2,4], l2 = [1,3,4]
+输出:[1,1,2,3,4,4]
+ +

示例 2:

+ +
+输入:l1 = [], l2 = []
+输出:[]
+ +

示例 3:

+ +
+输入:l1 = [], l2 = [0]
+输出:[0]
+ +

 

+ +

提示:

+ +

0 <= 链表长度 <= 1000

+ +

 

+ +

注意:本题与主站 21 题相同:https://leetcode-cn.com/problems/merge-two-sorted-lists/

+ +

 

diff --git a/leetcode-cn/problem (Chinese)/训练计划 V [liang-ge-lian-biao-de-di-yi-ge-gong-gong-jie-dian-lcof].html b/leetcode-cn/problem (Chinese)/训练计划 V [liang-ge-lian-biao-de-di-yi-ge-gong-gong-jie-dian-lcof].html new file mode 100644 index 00000000..d28371a4 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/训练计划 V [liang-ge-lian-biao-de-di-yi-ge-gong-gong-jie-dian-lcof].html @@ -0,0 +1,71 @@ +

某教练同时带教两位学员,分别以链表 l1l2 记录了两套核心肌群训练计划,节点值为训练项目编号。两套计划仅有前半部分热身项目不同,后续正式训练项目相同。请设计一个程序找出并返回第一个正式训练项目编号。如果两个链表不存在相交节点,返回 null

+ +

如下面的两个链表

+ +

+ +

在节点 c1 开始相交。

+ +

输入说明:

+ +

intersectVal - 相交的起始节点的值。如果不存在相交节点,这一值为 0

+ +

l1 - 第一个训练计划链表

+ +

l2 - 第二个训练计划链表

+ +

skip1 - 在 l1 中(从头节点开始)跳到交叉节点的节点数

+ +

skip2 - 在 l2 中(从头节点开始)跳到交叉节点的节点数

+ +

程序将根据这些输入创建链式数据结构,并将两个头节点 head1head2 传递给你的程序。如果程序能够正确返回相交节点,那么你的解决方案将被视作正确答案 。

+ +

 

+ +

示例 1:

+ +

+ +
+输入:intersectVal = 8, listA = [4,1,8,4,5], listB = [5,0,1,8,4,5], skipA = 2, skipB = 3
+输出:Reference of the node with value = 8
+解释:第一个正式训练项目编号为 8 (注意,如果两个列表相交则不能为 0)。从各自的表头开始算起,链表 A 为 [4,1,8,4,5],链表 B 为 [5,0,1,8,4,5]。在 A 中,相交节点前有 2 个节点;在 B 中,相交节点前有 3 个节点。
+
+ +

 

+ +

示例 2:

+ +

+ +
+输入:intersectVal = 2, listA = [0,9,1,2,4], listB = [3,2,4], skipA = 3, skipB = 1
+输出:Reference of the node with value = 2
+解释:第一个正式训练项目编号为 2 (注意,如果两个列表相交则不能为 0)。从各自的表头开始算起,链表 A 为 [0,9,1,2,4],链表 B 为 [3,2,4]。在 A 中,相交节点前有 3 个节点;在 B 中,相交节点前有 1 个节点。
+
+ +

 

+ +

示例 3:

+ +

+ +
+输入:intersectVal = 0, listA = [2,6,4], listB = [1,5], skipA = 3, skipB = 2
+输出:null
+解释:两套计划完全不同,返回 null。从各自的表头开始算起,链表 A 为 [2,6,4],链表 B 为 [1,5]。由于这两个链表不相交,所以 intersectVal 必须为 0,而 skipA 和 skipB 可以是任意值。
+
+ +

 

+ +

注意:

+ +
    +
  • 如果两个链表没有交点,返回 null.
  • +
  • 在返回结果后,两个链表仍须保持原有的结构。
  • +
  • 可假定整个链表结构中没有循环。
  • +
  • 程序尽量满足 O(n) 时间复杂度,且仅用 O(1) 内存。
  • +
  • 本题与主站 160 题相同:https://leetcode-cn.com/problems/intersection-of-two-linked-lists/
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/训练计划 VI [shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof].html b/leetcode-cn/problem (Chinese)/训练计划 VI [shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof].html new file mode 100644 index 00000000..9b7bef17 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/训练计划 VI [shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof].html @@ -0,0 +1,26 @@ +

教学过程中,教练示范一次,学员跟做三次。该过程被混乱剪辑后,记录于数组 actions,其中 actions[i] 表示做出该动作的人员编号。请返回教练的编号。

+ +

 

+ +

示例 1:

+ +
+输入:actions = [5, 7, 5, 5]
+输出:7
+
+ +

示例 2:

+ +
+输入:actions = [12, 1, 6, 12, 6, 12, 6]
+输出:1
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= actions.length <= 10000
  • +
  • 1 <= actions[i] < 2^31
  • +
diff --git a/leetcode-cn/problem (Chinese)/设计机械累加器 [qiu-12n-lcof].html b/leetcode-cn/problem (Chinese)/设计机械累加器 [qiu-12n-lcof].html new file mode 100644 index 00000000..8e92ba68 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/设计机械累加器 [qiu-12n-lcof].html @@ -0,0 +1,27 @@ +

请设计一个机械累加器,计算从 1、2... 一直累加到目标数值 target 的总和。注意这是一个只能进行加法操作的程序,不具备乘除、if-else、switch-case、for 循环、while 循环,及条件判断语句等高级功能。

+ +

 

+ +

示例 1:

+ +
+输入: target = 5
+输出: 15
+
+ +

示例 2:

+ +
+输入: target = 7
+输出: 28
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= target <= 10000
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/设计自助结算系统 [dui-lie-de-zui-da-zhi-lcof].html b/leetcode-cn/problem (Chinese)/设计自助结算系统 [dui-lie-de-zui-da-zhi-lcof].html new file mode 100644 index 00000000..b095aa01 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/设计自助结算系统 [dui-lie-de-zui-da-zhi-lcof].html @@ -0,0 +1,42 @@ +

请设计一个自助结账系统,该系统需要通过一个队列来模拟顾客通过购物车的结算过程,需要实现的功能有:

+ +
    +
  • get_max():获取结算商品中的最高价格,如果队列为空,则返回 -1
  • +
  • add(value):将价格为 value 的商品加入待结算商品队列的尾部
  • +
  • remove():移除第一个待结算的商品价格,如果队列为空,则返回 -1
  • +
+ +

注意,为保证该系统运转高效性,以上函数的均摊时间复杂度均为 O(1)

+ +

 

+ +

示例 1:

+ +
+输入: 
+["Checkout","add","add","get_max","remove","get_max"]
+[[],[4],[7],[],[],[]]
+
+输出: [null,null,null,7,4,7]
+
+ +

示例 2:

+ +
+输入: 
+["Checkout","remove","get_max"]
+[[],[],[]]
+
+输出: [null,-1,-1]
+
+ +

 

+ +

提示:

+ +
    +
  • 1 <= get_max, add, remove 的总操作数 <= 10000
  • +
  • 1 <= value <= 10^5
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/路径加密 [ti-huan-kong-ge-lcof].html b/leetcode-cn/problem (Chinese)/路径加密 [ti-huan-kong-ge-lcof].html new file mode 100644 index 00000000..6b51c070 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/路径加密 [ti-huan-kong-ge-lcof].html @@ -0,0 +1,18 @@ +

假定一段路径记作字符串 path,其中以 "." 作为分隔符。现需将路径加密,加密方法为将 path 中的分隔符替换为空格 " ",请返回加密后的字符串。

+ +

 

+ +

示例 1:

+ +
+输入:path = "a.aef.qerf.bb"
+
+输出:"a aef qerf bb"
+
+
+ +

 

+ +

限制:

+ +

0 <= path.length <= 10000

diff --git a/leetcode-cn/problem (Chinese)/跳跃训练 [qing-wa-tiao-tai-jie-wen-ti-lcof].html b/leetcode-cn/problem (Chinese)/跳跃训练 [qing-wa-tiao-tai-jie-wen-ti-lcof].html new file mode 100644 index 00000000..e99993f9 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/跳跃训练 [qing-wa-tiao-tai-jie-wen-ti-lcof].html @@ -0,0 +1,27 @@ +

今天的有氧运动训练内容是在一个长条形的平台上跳跃。平台有 num 个小格子,每次可以选择跳 一个格子 或者 两个格子。请返回在训练过程中,学员们共有多少种不同的跳跃方式。

+ +

结果可能过大,因此结果需要取模 1e9+7(1000000007),如计算初始结果为:1000000008,请返回 1。

+ +

示例 1:

+ +
+输入:n = 2
+输出:2
+
+ +

示例 2:

+ +
+输入:n = 5
+输出:8
+
+ +

 

+ +

提示:

+ +
    +
  • 0 <= n <= 100
  • +
+ +

注意:本题与主站 70 题相同:https://leetcode-cn.com/problems/climbing-stairs/

diff --git a/leetcode-cn/problem (Chinese)/连续天数的最高销售额 [lian-xu-zi-shu-zu-de-zui-da-he-lcof].html b/leetcode-cn/problem (Chinese)/连续天数的最高销售额 [lian-xu-zi-shu-zu-de-zui-da-he-lcof].html new file mode 100644 index 00000000..29fb0a47 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/连续天数的最高销售额 [lian-xu-zi-shu-zu-de-zui-da-he-lcof].html @@ -0,0 +1,30 @@ +

某公司每日销售额记于整数数组 sales,请返回所有 连续 一或多天销售额总和的最大值。

+ +

要求实现时间复杂度为 O(n) 的算法。

+ +

 

+ +

示例 1:

+ +
+输入:sales = [-2,1,-3,4,-1,2,1,-5,4]
+输出:6
+解释:[4,-1,2,1] 此连续四天的销售总额最高,为 6。
+ +

示例 2:

+ +
+输入:sales = [5,4,-1,7,8]
+输出:23
+解释:[5,4,-1,7,8] 此连续五天的销售总额最高,为 23。 
+ +

 

+ +

提示:

+ +
    +
  • 1 <= arr.length <= 10^5
  • +
  • -100 <= arr[i] <= 100
  • +
+ +

注意:本题与主站 53 题相同:https://leetcode-cn.com/problems/maximum-subarray/

diff --git a/leetcode-cn/problem (Chinese)/重命名列 [rename-columns].html b/leetcode-cn/problem (Chinese)/重命名列 [rename-columns].html new file mode 100644 index 00000000..9de41b45 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/重命名列 [rename-columns].html @@ -0,0 +1,50 @@ +
+DataFrame students
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| id          | int    |
+| first       | object |
+| last        | object |
+| age         | int    |
++-------------+--------+
+
+ +

编写一个解决方案,按以下方式重命名列:

+ +
    +
  • id 重命名为 student_id
  • +
  • first 重命名为 first_name
  • +
  • last 重命名为 last_name
  • +
  • age 重命名为 age_in_years
  • +
+ +

返回结果格式如下示例所示。

+ +

 

+ +

示例 1:

+ +
+输入:
++----+---------+----------+-----+
+| id | first   | last     | age |
++----+---------+----------+-----+
+| 1  | Mason   | King     | 6   |
+| 2  | Ava     | Wright   | 7   |
+| 3  | Taylor  | Hall     | 16  |
+| 4  | Georgia | Thompson | 18  |
+| 5  | Thomas  | Moore    | 10  |
++----+---------+----------+-----+
+输出:
++------------+------------+-----------+--------------+
+| student_id | first_name | last_name | age_in_years |
++------------+------------+-----------+--------------+
+| 1          | Mason      | King      | 6            |
+| 2          | Ava        | Wright    | 7            |
+| 3          | Taylor     | Hall      | 16           |
+| 4          | Georgia    | Thompson  | 18           |
+| 5          | Thomas     | Moore     | 10           |
++------------+------------+-----------+--------------+
+解释:
+列名已相应更换。
diff --git a/leetcode-cn/problem (Chinese)/重塑数据:融合 [reshape-data-melt].html b/leetcode-cn/problem (Chinese)/重塑数据:融合 [reshape-data-melt].html new file mode 100644 index 00000000..2cdcac5f --- /dev/null +++ b/leetcode-cn/problem (Chinese)/重塑数据:融合 [reshape-data-melt].html @@ -0,0 +1,45 @@ +
+DataFrame report
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| product     | object |
+| quarter_1   | int    |
+| quarter_2   | int    |
+| quarter_3   | int    |
+| quarter_4   | int    |
++-------------+--------+
+
+ +

编写一个解决方案,将数据 重塑 成每一行表示特定季度产品销售数据的形式。

+ +

结果格式如下例所示:

+ +

 

+ +

示例 1:

+ +
+输入:
++-------------+-----------+-----------+-----------+-----------+
+| product     | quarter_1 | quarter_2 | quarter_3 | quarter_4 |
++-------------+-----------+-----------+-----------+-----------+
+| Umbrella    | 417       | 224       | 379       | 611       |
+| SleepingBag | 800       | 936       | 93        | 875       |
++-------------+-----------+-----------+-----------+-----------+
+输出:
++-------------+-----------+-------+
+| product     | quarter   | sales |
++-------------+-----------+-------+
+| Umbrella    | quarter_1 | 417   |
+| SleepingBag | quarter_1 | 800   |
+| Umbrella    | quarter_2 | 224   |
+| SleepingBag | quarter_2 | 936   |
+| Umbrella    | quarter_3 | 379   |
+| SleepingBag | quarter_3 | 93    |
+| Umbrella    | quarter_4 | 611   |
+| SleepingBag | quarter_4 | 875   |
++-------------+-----------+-------+
+解释:
+DataFrame 已从宽格式重塑为长格式。每一行表示一个季度内产品的销售情况。
+
diff --git a/leetcode-cn/problem (Chinese)/重塑数据:连结 [reshape-data-concatenate].html b/leetcode-cn/problem (Chinese)/重塑数据:连结 [reshape-data-concatenate].html new file mode 100644 index 00000000..61540e63 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/重塑数据:连结 [reshape-data-concatenate].html @@ -0,0 +1,60 @@ +
+DataFrame df1
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| student_id  | int    |
+| name        | object |
+| age         | int    |
++-------------+--------+
+
+DataFrame df2
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| student_id  | int    |
+| name        | object |
+| age         | int    |
++-------------+--------+
+
+
+ +

编写一个解决方案,将两个 DataFrames 垂直 连接成一个 DataFrame。

+ +

结果格式如下示例所示。

+ +

 

+ +

示例 1:

+ +
+输入:
+df1
++------------+---------+-----+
+| student_id | name    | age |
++------------+---------+-----+
+| 1          | Mason   | 8   |
+| 2          | Ava     | 6   |
+| 3          | Taylor  | 15  |
+| 4          | Georgia | 17  |
++------------+---------+-----+
+df2
++------------+------+-----+
+| student_id | name | age |
++------------+------+-----+
+| 5          | Leo  | 7   |
+| 6          | Alex | 7   |
++------------+------+-----+
+输出:
++------------+---------+-----+
+| student_id | name    | age |
++------------+---------+-----+
+| 1          | Mason   | 8   |
+| 2          | Ava     | 6   |
+| 3          | Taylor  | 15  |
+| 4          | Georgia | 17  |
+| 5          | Leo     | 7   |
+| 6          | Alex    | 7   |
++------------+---------+-----+
+解释:
+两个 DataFrame 被垂直堆叠,它们的行被合并。
diff --git a/leetcode-cn/problem (Chinese)/项目员工 I [project-employees-i].html b/leetcode-cn/problem (Chinese)/项目员工 I [project-employees-i].html new file mode 100644 index 00000000..b3f39f12 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/项目员工 I [project-employees-i].html @@ -0,0 +1,63 @@ +

项目表 Project: 

+ +
++-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| project_id  | int     |
+| employee_id | int     |
++-------------+---------+
+主键为 (project_id, employee_id)。
+employee_id 是员工表 Employee 表的外键。
+
+ +

员工表 Employee

+ +
++------------------+---------+
+| Column Name      | Type    |
++------------------+---------+
+| employee_id      | int     |
+| name             | varchar |
+| experience_years | int     |
++------------------+---------+
+主键是 employee_id。
+
+ +

 

+ +

请写一个 SQL 语句,查询每一个项目中员工的 平均 工作年限,精确到小数点后两位

+ +

查询结果的格式如下:

+ +
+Project 表:
++-------------+-------------+
+| project_id  | employee_id |
++-------------+-------------+
+| 1           | 1           |
+| 1           | 2           |
+| 1           | 3           |
+| 2           | 1           |
+| 2           | 4           |
++-------------+-------------+
+
+Employee 表:
++-------------+--------+------------------+
+| employee_id | name   | experience_years |
++-------------+--------+------------------+
+| 1           | Khaled | 3                |
+| 2           | Ali    | 2                |
+| 3           | John   | 1                |
+| 4           | Doe    | 2                |
++-------------+--------+------------------+
+
+Result 表:
++-------------+---------------+
+| project_id  | average_years |
++-------------+---------------+
+| 1           | 2.00          |
+| 2           | 2.50          |
++-------------+---------------+
+第一个项目中,员工的平均工作年限是 (3 + 2 + 1) / 3 = 2.00;第二个项目中,员工的平均工作年限是 (3 + 2) / 2 = 2.50
+
diff --git a/leetcode-cn/problem (Chinese)/餐馆营业额变化增长 [restaurant-growth].html b/leetcode-cn/problem (Chinese)/餐馆营业额变化增长 [restaurant-growth].html new file mode 100644 index 00000000..ada54045 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/餐馆营业额变化增长 [restaurant-growth].html @@ -0,0 +1,63 @@ +

表: Customer

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| customer_id   | int     |
+| name          | varchar |
+| visited_on    | date    |
+| amount        | int     |
++---------------+---------+
+在 SQL 中,(customer_id, visited_on) 是该表的主键。
+该表包含一家餐馆的顾客交易数据。
+visited_on 表示 (customer_id) 的顾客在 visited_on 那天访问了餐馆。
+amount 是一个顾客某一天的消费总额。
+
+ +

 

+ +

你是餐馆的老板,现在你想分析一下可能的营业额变化增长(每天至少有一位顾客)。

+ +

计算以 7 天(某日期 + 该日期前的 6 天)为一个时间段的顾客消费平均值。average_amount 要 保留两位小数。

+ +

结果按 visited_on 升序排序

+ +

返回结果格式的例子如下。

+ +

 

+ +

示例 1:

+ +
+输入:
+Customer 表:
++-------------+--------------+--------------+-------------+
+| customer_id | name         | visited_on   | amount      |
++-------------+--------------+--------------+-------------+
+| 1           | Jhon         | 2019-01-01   | 100         |
+| 2           | Daniel       | 2019-01-02   | 110         |
+| 3           | Jade         | 2019-01-03   | 120         |
+| 4           | Khaled       | 2019-01-04   | 130         |
+| 5           | Winston      | 2019-01-05   | 110         | 
+| 6           | Elvis        | 2019-01-06   | 140         | 
+| 7           | Anna         | 2019-01-07   | 150         |
+| 8           | Maria        | 2019-01-08   | 80          |
+| 9           | Jaze         | 2019-01-09   | 110         | 
+| 1           | Jhon         | 2019-01-10   | 130         | 
+| 3           | Jade         | 2019-01-10   | 150         | 
++-------------+--------------+--------------+-------------+
+输出:
++--------------+--------------+----------------+
+| visited_on   | amount       | average_amount |
++--------------+--------------+----------------+
+| 2019-01-07   | 860          | 122.86         |
+| 2019-01-08   | 840          | 120            |
+| 2019-01-09   | 840          | 120            |
+| 2019-01-10   | 1000         | 142.86         |
++--------------+--------------+----------------+
+解释:
+第一个七天消费平均值从 2019-01-01 到 2019-01-07 是restaurant-growth/restaurant-growth/ (100 + 110 + 120 + 130 + 110 + 140 + 150)/7 = 122.86
+第二个七天消费平均值从 2019-01-02 到 2019-01-08 是 (110 + 120 + 130 + 110 + 140 + 150 + 80)/7 = 120
+第三个七天消费平均值从 2019-01-03 到 2019-01-09 是 (120 + 130 + 110 + 140 + 150 + 80 + 110)/7 = 120
+第四个七天消费平均值从 2019-01-04 到 2019-01-10 是 (130 + 110 + 140 + 150 + 80 + 110 + 130 + 150)/7 = 142.86
diff --git a/leetcode-cn/problem (Chinese)/验证二叉搜索树的后序遍历序列 [er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof].html b/leetcode-cn/problem (Chinese)/验证二叉搜索树的后序遍历序列 [er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof].html new file mode 100644 index 00000000..084c01d8 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/验证二叉搜索树的后序遍历序列 [er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof].html @@ -0,0 +1,34 @@ +

请实现一个函数来判断整数数组 postorder 是否为二叉搜索树的后序遍历结果。

+ +

 

+ +

示例 1:

+ +

+ +
+输入: postorder = [4,9,6,9,8]
+输出: false 
+解释:从上图可以看出这不是一颗二叉搜索树
+
+ +

示例 2:

+ +

+ +
+输入: postorder = [4,6,5,9,8]
+输出: true 
+解释:可构建的二叉搜索树如上图
+
+ +

 

+ +

提示:

+ +
    +
  • 数组长度 <= 1000
  • +
  • postorder 中无重复数字
  • +
+ +

 

diff --git a/leetcode-cn/problem (Chinese)/验证回文串 II [valid-palindrome-ii].html b/leetcode-cn/problem (Chinese)/验证回文串 II [valid-palindrome-ii].html new file mode 100644 index 00000000..287e1bb0 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/验证回文串 II [valid-palindrome-ii].html @@ -0,0 +1,35 @@ +

给你一个字符串 s最多 可以从中删除一个字符。

+ +

请你判断 s 是否能成为回文字符串:如果能,返回 true ;否则,返回 false

+ +

 

+ +

示例 1:

+ +
+输入:s = "aba"
+输出:true
+
+ +

示例 2:

+ +
+输入:s = "abca"
+输出:true
+解释:你可以删除字符 'c' 。
+
+ +

示例 3:

+ +
+输入:s = "abc"
+输出:false
+ +

 

+ +

提示:

+ +
    +
  • 1 <= s.length <= 105
  • +
  • s 由小写英文字母组成
  • +
diff --git a/leetcode-cn/problem (Chinese)/验证图书取出顺序 [zhan-de-ya-ru-dan-chu-xu-lie-lcof].html b/leetcode-cn/problem (Chinese)/验证图书取出顺序 [zhan-de-ya-ru-dan-chu-xu-lie-lcof].html new file mode 100644 index 00000000..15ee3e70 --- /dev/null +++ b/leetcode-cn/problem (Chinese)/验证图书取出顺序 [zhan-de-ya-ru-dan-chu-xu-lie-lcof].html @@ -0,0 +1,37 @@ +

现在图书馆有一堆图书需要放入书架,并且图书馆的书架是一种特殊的数据结构,只能按照 一定 的顺序 放入拿取 书籍。

+ +

给定一个表示图书放入顺序的整数序列 putIn,请判断序列 takeOut 是否为按照正确的顺序拿取书籍的操作序列。你可以假设放入书架的所有书籍编号都不相同。

+ +

 

+ +

示例 1:

+ +
+输入:putIn = [6,7,8,9,10,11], takeOut = [9,11,10,8,7,6]
+输出:true
+解释:我们可以按以下操作放入并拿取书籍:
+push(6), push(7), push(8), push(9), pop() -> 9,
+push(10), push(11),pop() -> 11,pop() -> 10, pop() -> 8, pop() -> 7, pop() -> 6
+
+ +

示例 2:

+ +
+输入:putIn = [6,7,8,9,10,11], takeOut = [11,9,8,10,6,7]
+输出:false
+解释:6 不能在 7 之前取出。
+
+ +

 

+ +

提示:

+ +
    +
  • 0 <= putIn.length == takeOut.length <= 1000
  • +
  • 0 <= putIn[i], takeOut < 1000
  • +
  • putIntakeOut 的排列。
  • +
+ +

注意:本题与主站 946 题相同:https://leetcode-cn.com/problems/validate-stack-sequences/

+ +

 

diff --git a/leetcode-cn/problem (English)/2016年的投资(English) [investments-in-2016].html b/leetcode-cn/problem (English)/2016年的投资(English) [investments-in-2016].html new file mode 100644 index 00000000..c85babba --- /dev/null +++ b/leetcode-cn/problem (English)/2016年的投资(English) [investments-in-2016].html @@ -0,0 +1,60 @@ +

Table: Insurance

+ +
++-------------+-------+
+| Column Name | Type  |
++-------------+-------+
+| pid         | int   |
+| tiv_2015    | float |
+| tiv_2016    | float |
+| lat         | float |
+| lon         | float |
++-------------+-------+
+pid is the primary key (column with unique values) for this table.
+Each row of this table contains information about one policy where:
+pid is the policyholder's policy ID.
+tiv_2015 is the total investment value in 2015 and tiv_2016 is the total investment value in 2016.
+lat is the latitude of the policy holder's city. It's guaranteed that lat is not NULL.
+lon is the longitude of the policy holder's city. It's guaranteed that lon is not NULL.
+
+ +

 

+ +

Write a solution to report the sum of all total investment values in 2016 tiv_2016, for all policyholders who:

+ +
    +
  • have the same tiv_2015 value as one or more other policyholders, and
  • +
  • are not located in the same city as any other policyholder (i.e., the (lat, lon) attribute pairs must be unique).
  • +
+ +

Round tiv_2016 to two decimal places.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Insurance table:
++-----+----------+----------+-----+-----+
+| pid | tiv_2015 | tiv_2016 | lat | lon |
++-----+----------+----------+-----+-----+
+| 1   | 10       | 5        | 10  | 10  |
+| 2   | 20       | 20       | 20  | 20  |
+| 3   | 10       | 30       | 20  | 20  |
+| 4   | 10       | 40       | 40  | 40  |
++-----+----------+----------+-----+-----+
+Output: 
++----------+
+| tiv_2016 |
++----------+
+| 45.00    |
++----------+
+Explanation: 
+The first record in the table, like the last record, meets both of the two criteria.
+The tiv_2015 value 10 is the same as the third and fourth records, and its location is unique.
+
+The second record does not meet any of the two criteria. Its tiv_2015 is not like any other policyholders and its location is the same as the third record, which makes the third record fail, too.
+So, the result is the sum of tiv_2016 of the first and last record, which is 45.
+
diff --git a/leetcode-cn/problem (English)/上级经理已离职的公司员工(English) [employees-whose-manager-left-the-company].html b/leetcode-cn/problem (English)/上级经理已离职的公司员工(English) [employees-whose-manager-left-the-company].html new file mode 100644 index 00000000..62db0908 --- /dev/null +++ b/leetcode-cn/problem (English)/上级经理已离职的公司员工(English) [employees-whose-manager-left-the-company].html @@ -0,0 +1,51 @@ +

Table: Employees

+ +
++-------------+----------+
+| Column Name | Type     |
++-------------+----------+
+| employee_id | int      |
+| name        | varchar  |
+| manager_id  | int      |
+| salary      | int      |
++-------------+----------+
+In SQL, employee_id is the primary key for this table.
+This table contains information about the employees, their salary, and the ID of their manager. Some employees do not have a manager (manager_id is null). 
+
+ +

 

+ +

Find the IDs of the employees whose salary is strictly less than $30000 and whose manager left the company. When a manager leaves the company, their information is deleted from the Employees table, but the reports still have their manager_id set to the manager that left.

+ +

Return the result table ordered by employee_id.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input:  
+Employees table:
++-------------+-----------+------------+--------+
+| employee_id | name      | manager_id | salary |
++-------------+-----------+------------+--------+
+| 3           | Mila      | 9          | 60301  |
+| 12          | Antonella | null       | 31000  |
+| 13          | Emery     | null       | 67084  |
+| 1           | Kalel     | 11         | 21241  |
+| 9           | Mikaela   | null       | 50937  |
+| 11          | Joziah    | 6          | 28485  |
++-------------+-----------+------------+--------+
+Output: 
++-------------+
+| employee_id |
++-------------+
+| 11          |
++-------------+
+
+Explanation: 
+The employees with a salary less than $30000 are 1 (Kalel) and 11 (Joziah).
+Kalel's manager is employee 11, who is still in the company (Joziah).
+Joziah's manager is employee 6, who left the company because there is no row for employee 6 as it was deleted.
+
diff --git a/leetcode-cn/problem (English)/买下所有产品的客户(English) [customers-who-bought-all-products].html b/leetcode-cn/problem (English)/买下所有产品的客户(English) [customers-who-bought-all-products].html new file mode 100644 index 00000000..867e330d --- /dev/null +++ b/leetcode-cn/problem (English)/买下所有产品的客户(English) [customers-who-bought-all-products].html @@ -0,0 +1,67 @@ +

Table: Customer

+ +
++-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| customer_id | int     |
+| product_key | int     |
++-------------+---------+
+This table may contain duplicates rows. 
+customer_id is not NULL.
+product_key is a foreign key (reference column) to Product table.
+
+ +

 

+ +

Table: Product

+ +
++-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| product_key | int     |
++-------------+---------+
+product_key is the primary key (column with unique values) for this table.
+
+ +

 

+ +

Write a solution to report the customer ids from the Customer table that bought all the products in the Product table.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Customer table:
++-------------+-------------+
+| customer_id | product_key |
++-------------+-------------+
+| 1           | 5           |
+| 2           | 6           |
+| 3           | 5           |
+| 3           | 6           |
+| 1           | 6           |
++-------------+-------------+
+Product table:
++-------------+
+| product_key |
++-------------+
+| 5           |
+| 6           |
++-------------+
+Output: 
++-------------+
+| customer_id |
++-------------+
+| 1           |
+| 3           |
++-------------+
+Explanation: 
+The customers who bought all the products (5 and 6) are customers with IDs 1 and 3.
+
diff --git a/leetcode-cn/problem (English)/产品销售分析 I(English) [product-sales-analysis-i].html b/leetcode-cn/problem (English)/产品销售分析 I(English) [product-sales-analysis-i].html new file mode 100644 index 00000000..13c17200 --- /dev/null +++ b/leetcode-cn/problem (English)/产品销售分析 I(English) [product-sales-analysis-i].html @@ -0,0 +1,75 @@ +

Table: Sales

+ +
++-------------+-------+
+| Column Name | Type  |
++-------------+-------+
+| sale_id     | int   |
+| product_id  | int   |
+| year        | int   |
+| quantity    | int   |
+| price       | int   |
++-------------+-------+
+(sale_id, year) is the primary key (combination of columns with unique values) of this table.
+product_id is a foreign key (reference column) to Product table.
+Each row of this table shows a sale on the product product_id in a certain year.
+Note that the price is per unit.
+
+ +

 

+ +

Table: Product

+ +
++--------------+---------+
+| Column Name  | Type    |
++--------------+---------+
+| product_id   | int     |
+| product_name | varchar |
++--------------+---------+
+product_id is the primary key (column with unique values) of this table.
+Each row of this table indicates the product name of each product.
+
+ +

 

+ +

Write a solution to report the product_name, year, and price for each sale_id in the Sales table.

+ +

Return the resulting table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Sales table:
++---------+------------+------+----------+-------+
+| sale_id | product_id | year | quantity | price |
++---------+------------+------+----------+-------+ 
+| 1       | 100        | 2008 | 10       | 5000  |
+| 2       | 100        | 2009 | 12       | 5000  |
+| 7       | 200        | 2011 | 15       | 9000  |
++---------+------------+------+----------+-------+
+Product table:
++------------+--------------+
+| product_id | product_name |
++------------+--------------+
+| 100        | Nokia        |
+| 200        | Apple        |
+| 300        | Samsung      |
++------------+--------------+
+Output: 
++--------------+-------+-------+
+| product_name | year  | price |
++--------------+-------+-------+
+| Nokia        | 2008  | 5000  |
+| Nokia        | 2009  | 5000  |
+| Apple        | 2011  | 9000  |
++--------------+-------+-------+
+Explanation: 
+From sale_id = 1, we can conclude that Nokia was sold for 5000 in the year 2008.
+From sale_id = 2, we can conclude that Nokia was sold for 5000 in the year 2009.
+From sale_id = 7, we can conclude that Apple was sold for 9000 in the year 2011.
+
diff --git a/leetcode-cn/problem (English)/产品销售分析 III(English) [product-sales-analysis-iii].html b/leetcode-cn/problem (English)/产品销售分析 III(English) [product-sales-analysis-iii].html new file mode 100644 index 00000000..ccdcfe79 --- /dev/null +++ b/leetcode-cn/problem (English)/产品销售分析 III(English) [product-sales-analysis-iii].html @@ -0,0 +1,70 @@ +

Table: Sales

+ +
++-------------+-------+
+| Column Name | Type  |
++-------------+-------+
+| sale_id     | int   |
+| product_id  | int   |
+| year        | int   |
+| quantity    | int   |
+| price       | int   |
++-------------+-------+
+(sale_id, year) is the primary key (combination of columns with unique values) of this table.
+product_id is a foreign key (reference column) to Product table.
+Each row of this table shows a sale on the product product_id in a certain year.
+Note that the price is per unit.
+
+ +

 

+ +

Table: Product

+ +
++--------------+---------+
+| Column Name  | Type    |
++--------------+---------+
+| product_id   | int     |
+| product_name | varchar |
++--------------+---------+
+product_id is the primary key (column with unique values) of this table.
+Each row of this table indicates the product name of each product.
+
+ +

 

+ +

Write a solution to select the product id, year, quantity, and price for the first year of every product sold.

+ +

Return the resulting table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Sales table:
++---------+------------+------+----------+-------+
+| sale_id | product_id | year | quantity | price |
++---------+------------+------+----------+-------+ 
+| 1       | 100        | 2008 | 10       | 5000  |
+| 2       | 100        | 2009 | 12       | 5000  |
+| 7       | 200        | 2011 | 15       | 9000  |
++---------+------------+------+----------+-------+
+Product table:
++------------+--------------+
+| product_id | product_name |
++------------+--------------+
+| 100        | Nokia        |
+| 200        | Apple        |
+| 300        | Samsung      |
++------------+--------------+
+Output: 
++------------+------------+----------+-------+
+| product_id | first_year | quantity | price |
++------------+------------+----------+-------+ 
+| 100        | 2008       | 10       | 5000  |
+| 200        | 2011       | 15       | 9000  |
++------------+------------+----------+-------+
+
diff --git a/leetcode-cn/problem (English)/从表中创建 DataFrame(English) [create-a-dataframe-from-list].html b/leetcode-cn/problem (English)/从表中创建 DataFrame(English) [create-a-dataframe-from-list].html new file mode 100644 index 00000000..64f2656f --- /dev/null +++ b/leetcode-cn/problem (English)/从表中创建 DataFrame(English) [create-a-dataframe-from-list].html @@ -0,0 +1,30 @@ +

Write a solution to create a DataFrame from a 2D list called student_data. This 2D list contains the IDs and ages of some students.

+ +

The DataFrame should have two columns, student_id and age, and be in the same order as the original 2D list.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input:
+student_data:
+[
+  [1, 15],
+  [2, 11],
+  [3, 11],
+  [4, 20]
+]
+Output:
++------------+-----+
+| student_id | age |
++------------+-----+
+| 1          | 15  |
+| 2          | 11  |
+| 3          | 11  |
+| 4          | 20  |
++------------+-----+
+Explanation:
+A DataFrame was created on top of student_data, with two columns named student_id and age.
+
diff --git a/leetcode-cn/problem (English)/使用唯一标识码替换员工ID(English) [replace-employee-id-with-the-unique-identifier].html b/leetcode-cn/problem (English)/使用唯一标识码替换员工ID(English) [replace-employee-id-with-the-unique-identifier].html new file mode 100644 index 00000000..4efabdae --- /dev/null +++ b/leetcode-cn/problem (English)/使用唯一标识码替换员工ID(English) [replace-employee-id-with-the-unique-identifier].html @@ -0,0 +1,75 @@ +

Table: Employees

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| id            | int     |
+| name          | varchar |
++---------------+---------+
+id is the primary key (column with unique values) for this table.
+Each row of this table contains the id and the name of an employee in a company.
+
+ +

 

+ +

Table: EmployeeUNI

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| id            | int     |
+| unique_id     | int     |
++---------------+---------+
+(id, unique_id) is the primary key (combination of columns with unique values) for this table.
+Each row of this table contains the id and the corresponding unique id of an employee in the company.
+
+ +

 

+ +

Write a solution to show the unique ID of each user, If a user does not have a unique ID replace just show null.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Employees table:
++----+----------+
+| id | name     |
++----+----------+
+| 1  | Alice    |
+| 7  | Bob      |
+| 11 | Meir     |
+| 90 | Winston  |
+| 3  | Jonathan |
++----+----------+
+EmployeeUNI table:
++----+-----------+
+| id | unique_id |
++----+-----------+
+| 3  | 1         |
+| 11 | 2         |
+| 90 | 3         |
++----+-----------+
+Output: 
++-----------+----------+
+| unique_id | name     |
++-----------+----------+
+| null      | Alice    |
+| null      | Bob      |
+| 2         | Meir     |
+| 3         | Winston  |
+| 1         | Jonathan |
++-----------+----------+
+Explanation: 
+Alice and Bob do not have a unique ID, We will show null instead.
+The unique ID of Meir is 2.
+The unique ID of Winston is 3.
+The unique ID of Jonathan is 1.
+
diff --git a/leetcode-cn/problem (English)/修改列(English) [modify-columns].html b/leetcode-cn/problem (English)/修改列(English) [modify-columns].html new file mode 100644 index 00000000..2556499e --- /dev/null +++ b/leetcode-cn/problem (English)/修改列(English) [modify-columns].html @@ -0,0 +1,41 @@ +
+DataFrame employees
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| name        | object |
+| salary      | int    |
++-------------+--------+
+
+ +

A company intends to give its employees a pay rise.

+ +

Write a solution to modify the salary column by multiplying each salary by 2.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input:
+DataFrame employees
++---------+--------+
+| name    | salary |
++---------+--------+
+| Jack    | 19666  |
+| Piper   | 74754  |
+| Mia     | 62509  |
+| Ulysses | 54866  |
++---------+--------+
+Output:
++---------+--------+
+| name    | salary |
++---------+--------+
+| Jack    | 39332  |
+| Piper   | 149508 |
+| Mia     | 125018 |
+| Ulysses | 109732 |
++---------+--------+
+Explanation:
+Every salary has been doubled.
diff --git a/leetcode-cn/problem (English)/列出指定时间段内所有的下单产品(English) [list-the-products-ordered-in-a-period].html b/leetcode-cn/problem (English)/列出指定时间段内所有的下单产品(English) [list-the-products-ordered-in-a-period].html new file mode 100644 index 00000000..bc382144 --- /dev/null +++ b/leetcode-cn/problem (English)/列出指定时间段内所有的下单产品(English) [list-the-products-ordered-in-a-period].html @@ -0,0 +1,85 @@ +

Table: Products

+ +
++------------------+---------+
+| Column Name      | Type    |
++------------------+---------+
+| product_id       | int     |
+| product_name     | varchar |
+| product_category | varchar |
++------------------+---------+
+product_id is the primary key (column with unique values) for this table.
+This table contains data about the company's products.
+
+ +

 

+ +

Table: Orders

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| product_id    | int     |
+| order_date    | date    |
+| unit          | int     |
++---------------+---------+
+This table may have duplicate rows.
+product_id is a foreign key (reference column) to the Products table.
+unit is the number of products ordered in order_date.
+
+ +

 

+ +

Write a solution to get the names of products that have at least 100 units ordered in February 2020 and their amount.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Products table:
++-------------+-----------------------+------------------+
+| product_id  | product_name          | product_category |
++-------------+-----------------------+------------------+
+| 1           | Leetcode Solutions    | Book             |
+| 2           | Jewels of Stringology | Book             |
+| 3           | HP                    | Laptop           |
+| 4           | Lenovo                | Laptop           |
+| 5           | Leetcode Kit          | T-shirt          |
++-------------+-----------------------+------------------+
+Orders table:
++--------------+--------------+----------+
+| product_id   | order_date   | unit     |
++--------------+--------------+----------+
+| 1            | 2020-02-05   | 60       |
+| 1            | 2020-02-10   | 70       |
+| 2            | 2020-01-18   | 30       |
+| 2            | 2020-02-11   | 80       |
+| 3            | 2020-02-17   | 2        |
+| 3            | 2020-02-24   | 3        |
+| 4            | 2020-03-01   | 20       |
+| 4            | 2020-03-04   | 30       |
+| 4            | 2020-03-04   | 60       |
+| 5            | 2020-02-25   | 50       |
+| 5            | 2020-02-27   | 50       |
+| 5            | 2020-03-01   | 50       |
++--------------+--------------+----------+
+Output: 
++--------------------+---------+
+| product_name       | unit    |
++--------------------+---------+
+| Leetcode Solutions | 130     |
+| Leetcode Kit       | 100     |
++--------------------+---------+
+Explanation: 
+Products with product_id = 1 is ordered in February a total of (60 + 70) = 130.
+Products with product_id = 2 is ordered in February a total of 80.
+Products with product_id = 3 is ordered in February a total of (2 + 3) = 5.
+Products with product_id = 4 was not ordered in February 2020.
+Products with product_id = 5 is ordered in February a total of (50 + 50) = 100.
+
diff --git a/leetcode-cn/problem (English)/创建新列(English) [create-a-new-column].html b/leetcode-cn/problem (English)/创建新列(English) [create-a-new-column].html new file mode 100644 index 00000000..ac5b6b79 --- /dev/null +++ b/leetcode-cn/problem (English)/创建新列(English) [create-a-new-column].html @@ -0,0 +1,45 @@ +
+DataFrame employees
++-------------+--------+
+| Column Name | Type.  |
++-------------+--------+
+| name        | object |
+| salary      | int.   |
++-------------+--------+
+
+ +

A company plans to provide its employees with a bonus.

+ +

Write a solution to create a new column name bonus that contains the doubled values of the salary column.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input:
+DataFrame employees
++---------+--------+
+| name    | salary |
++---------+--------+
+| Piper   | 4548   |
+| Grace   | 28150  |
+| Georgia | 1103   |
+| Willow  | 6593   |
+| Finn    | 74576  |
+| Thomas  | 24433  |
++---------+--------+
+Output:
++---------+--------+--------+
+| name    | salary | bonus  |
++---------+--------+--------+
+| Piper   | 4548   | 9096   |
+| Grace   | 28150  | 56300  |
+| Georgia | 1103   | 2206   |
+| Willow  | 6593   | 13186  |
+| Finn    | 74576  | 149152 |
+| Thomas  | 24433  | 48866  |
++---------+--------+--------+
+Explanation: 
+A new column bonus is created by doubling the value in the column salary.
diff --git a/leetcode-cn/problem (English)/删去丢失的数据(English) [drop-missing-data].html b/leetcode-cn/problem (English)/删去丢失的数据(English) [drop-missing-data].html new file mode 100644 index 00000000..05fa15eb --- /dev/null +++ b/leetcode-cn/problem (English)/删去丢失的数据(English) [drop-missing-data].html @@ -0,0 +1,40 @@ +
+DataFrame students
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| student_id  | int    |
+| name        | object |
+| age         | int    |
++-------------+--------+
+
+ +

There are some rows having missing values in the name column.

+ +

Write a solution to remove the rows with missing values.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input:
++------------+---------+-----+
+| student_id | name    | age |
++------------+---------+-----+
+| 32         | Piper   | 5   |
+| 217        | None    | 19  |
+| 779        | Georgia | 20  |
+| 849        | Willow  | 14  |
++------------+---------+-----+
+Output:
++------------+---------+-----+
+| student_id | name    | age |
++------------+---------+-----+
+| 32         | Piper   | 5   |
+| 779        | Georgia | 20  | 
+| 849        | Willow  | 14  | 
++------------+---------+-----+
+Explanation: 
+Student with id 217 havs empty value in the name column, so it will be removed.
diff --git a/leetcode-cn/problem (English)/删去重复的行(English) [drop-duplicate-rows].html b/leetcode-cn/problem (English)/删去重复的行(English) [drop-duplicate-rows].html new file mode 100644 index 00000000..74d4e8d5 --- /dev/null +++ b/leetcode-cn/problem (English)/删去重复的行(English) [drop-duplicate-rows].html @@ -0,0 +1,44 @@ +
+DataFrame customers
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| customer_id | int    |
+| name        | object |
+| email       | object |
++-------------+--------+
+
+ +

There are some duplicate rows in the DataFrame based on the email column.

+ +

Write a solution to remove these duplicate rows and keep only the first occurrence.

+ +

The result format is in the following example.

+ +

 

+
+Example 1:
+Input:
++-------------+---------+---------------------+
+| customer_id | name    | email               |
++-------------+---------+---------------------+
+| 1           | Ella    | emily@example.com   |
+| 2           | David   | michael@example.com |
+| 3           | Zachary | sarah@example.com   |
+| 4           | Alice   | john@example.com    |
+| 5           | Finn    | john@example.com    |
+| 6           | Violet  | alice@example.com   |
++-------------+---------+---------------------+
+Output:  
++-------------+---------+---------------------+
+| customer_id | name    | email               |
++-------------+---------+---------------------+
+| 1           | Ella    | emily@example.com   |
+| 2           | David   | michael@example.com |
+| 3           | Zachary | sarah@example.com   |
+| 4           | Alice   | john@example.com    |
+| 6           | Violet  | alice@example.com   |
++-------------+---------+---------------------+
+Explanation:
+Alic (customer_id = 4) and Finn (customer_id = 5) both use john@example.com, so only the first occurrence of this email is retained.
+
diff --git a/leetcode-cn/problem (English)/判断三角形(English) [triangle-judgement].html b/leetcode-cn/problem (English)/判断三角形(English) [triangle-judgement].html new file mode 100644 index 00000000..be0f4a98 --- /dev/null +++ b/leetcode-cn/problem (English)/判断三角形(English) [triangle-judgement].html @@ -0,0 +1,42 @@ +

Table: Triangle

+ +
++-------------+------+
+| Column Name | Type |
++-------------+------+
+| x           | int  |
+| y           | int  |
+| z           | int  |
++-------------+------+
+In SQL, (x, y, z) is the primary key column for this table.
+Each row of this table contains the lengths of three line segments.
+
+ +

 

+ +

Report for every three line segments whether they can form a triangle.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Triangle table:
++----+----+----+
+| x  | y  | z  |
++----+----+----+
+| 13 | 15 | 30 |
+| 10 | 20 | 15 |
++----+----+----+
+Output: 
++----+----+----+----------+
+| x  | y  | z  | triangle |
++----+----+----+----------+
+| 13 | 15 | 30 | No       |
+| 10 | 20 | 15 | Yes      |
++----+----+----+----------+
+
diff --git a/leetcode-cn/problem (English)/即时食物配送 II(English) [immediate-food-delivery-ii].html b/leetcode-cn/problem (English)/即时食物配送 II(English) [immediate-food-delivery-ii].html new file mode 100644 index 00000000..181fac50 --- /dev/null +++ b/leetcode-cn/problem (English)/即时食物配送 II(English) [immediate-food-delivery-ii].html @@ -0,0 +1,55 @@ +

Table: Delivery

+ +
++-----------------------------+---------+
+| Column Name                 | Type    |
++-----------------------------+---------+
+| delivery_id                 | int     |
+| customer_id                 | int     |
+| order_date                  | date    |
+| customer_pref_delivery_date | date    |
++-----------------------------+---------+
+delivery_id is the column of unique values of this table.
+The table holds information about food delivery to customers that make orders at some date and specify a preferred delivery date (on the same order date or after it).
+
+ +

 

+ +

If the customer's preferred delivery date is the same as the order date, then the order is called immediate; otherwise, it is called scheduled.

+ +

The first order of a customer is the order with the earliest order date that the customer made. It is guaranteed that a customer has precisely one first order.

+ +

Write a solution to find the percentage of immediate orders in the first orders of all customers, rounded to 2 decimal places.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Delivery table:
++-------------+-------------+------------+-----------------------------+
+| delivery_id | customer_id | order_date | customer_pref_delivery_date |
++-------------+-------------+------------+-----------------------------+
+| 1           | 1           | 2019-08-01 | 2019-08-02                  |
+| 2           | 2           | 2019-08-02 | 2019-08-02                  |
+| 3           | 1           | 2019-08-11 | 2019-08-12                  |
+| 4           | 3           | 2019-08-24 | 2019-08-24                  |
+| 5           | 3           | 2019-08-21 | 2019-08-22                  |
+| 6           | 2           | 2019-08-11 | 2019-08-13                  |
+| 7           | 4           | 2019-08-09 | 2019-08-09                  |
++-------------+-------------+------------+-----------------------------+
+Output: 
++----------------------+
+| immediate_percentage |
++----------------------+
+| 50.00                |
++----------------------+
+Explanation: 
+The customer id 1 has a first order with delivery id 1 and it is scheduled.
+The customer id 2 has a first order with delivery id 2 and it is immediate.
+The customer id 3 has a first order with delivery id 5 and it is scheduled.
+The customer id 4 has a first order with delivery id 7 and it is immediate.
+Hence, half the customers have immediate first orders.
+
diff --git a/leetcode-cn/problem (English)/只出现一次的最大数字(English) [biggest-single-number].html b/leetcode-cn/problem (English)/只出现一次的最大数字(English) [biggest-single-number].html new file mode 100644 index 00000000..b99439e1 --- /dev/null +++ b/leetcode-cn/problem (English)/只出现一次的最大数字(English) [biggest-single-number].html @@ -0,0 +1,72 @@ +

Table: MyNumbers

+ +
++-------------+------+
+| Column Name | Type |
++-------------+------+
+| num         | int  |
++-------------+------+
+This table may contain duplicates (In other words, there is no primary key for this table in SQL).
+Each row of this table contains an integer.
+
+ +

 

+ +

A single number is a number that appeared only once in the MyNumbers table.

+ +

Find the largest single number. If there is no single number, report null.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+MyNumbers table:
++-----+
+| num |
++-----+
+| 8   |
+| 8   |
+| 3   |
+| 3   |
+| 1   |
+| 4   |
+| 5   |
+| 6   |
++-----+
+Output: 
++-----+
+| num |
++-----+
+| 6   |
++-----+
+Explanation: The single numbers are 1, 4, 5, and 6.
+Since 6 is the largest single number, we return it.
+
+ +

Example 2:

+ +
+Input: 
+MyNumbers table:
++-----+
+| num |
++-----+
+| 8   |
+| 8   |
+| 7   |
+| 7   |
+| 3   |
+| 3   |
+| 3   |
++-----+
+Output: 
++------+
+| num  |
++------+
+| null |
++------+
+Explanation: There are no single numbers in the input table so we return null.
+
diff --git a/leetcode-cn/problem (English)/各赛事的用户注册率(English) [percentage-of-users-attended-a-contest].html b/leetcode-cn/problem (English)/各赛事的用户注册率(English) [percentage-of-users-attended-a-contest].html new file mode 100644 index 00000000..e13a191a --- /dev/null +++ b/leetcode-cn/problem (English)/各赛事的用户注册率(English) [percentage-of-users-attended-a-contest].html @@ -0,0 +1,81 @@ +

Table: Users

+ +
++-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| user_id     | int     |
+| user_name   | varchar |
++-------------+---------+
+user_id is the primary key (column with unique values) for this table.
+Each row of this table contains the name and the id of a user.
+
+ +

 

+ +

Table: Register

+ +
++-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| contest_id  | int     |
+| user_id     | int     |
++-------------+---------+
+(contest_id, user_id) is the primary key (combination of columns with unique values) for this table.
+Each row of this table contains the id of a user and the contest they registered into.
+
+ +

 

+ +

Write a solution to find the percentage of the users registered in each contest rounded to two decimals.

+ +

Return the result table ordered by percentage in descending order. In case of a tie, order it by contest_id in ascending order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Users table:
++---------+-----------+
+| user_id | user_name |
++---------+-----------+
+| 6       | Alice     |
+| 2       | Bob       |
+| 7       | Alex      |
++---------+-----------+
+Register table:
++------------+---------+
+| contest_id | user_id |
++------------+---------+
+| 215        | 6       |
+| 209        | 2       |
+| 208        | 2       |
+| 210        | 6       |
+| 208        | 6       |
+| 209        | 7       |
+| 209        | 6       |
+| 215        | 7       |
+| 208        | 7       |
+| 210        | 2       |
+| 207        | 2       |
+| 210        | 7       |
++------------+---------+
+Output: 
++------------+------------+
+| contest_id | percentage |
++------------+------------+
+| 208        | 100.0      |
+| 209        | 100.0      |
+| 210        | 100.0      |
+| 215        | 66.67      |
+| 207        | 33.33      |
++------------+------------+
+Explanation: 
+All the users registered in contests 208, 209, and 210. The percentage is 100% and we sort them in the answer table by contest_id in ascending order.
+Alice and Alex registered in contest 215 and the percentage is ((2/3) * 100) = 66.67%
+Bob registered in contest 207 and the percentage is ((1/3) * 100) = 33.33%
+
diff --git a/leetcode-cn/problem (English)/员工奖金(English) [employee-bonus].html b/leetcode-cn/problem (English)/员工奖金(English) [employee-bonus].html new file mode 100644 index 00000000..5e370b53 --- /dev/null +++ b/leetcode-cn/problem (English)/员工奖金(English) [employee-bonus].html @@ -0,0 +1,69 @@ +

Table: Employee

+ +
++-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| empId       | int     |
+| name        | varchar |
+| supervisor  | int     |
+| salary      | int     |
++-------------+---------+
+empId is the column with unique values for this table.
+Each row of this table indicates the name and the ID of an employee in addition to their salary and the id of their manager.
+
+ +

 

+ +

Table: Bonus

+ +
++-------------+------+
+| Column Name | Type |
++-------------+------+
+| empId       | int  |
+| bonus       | int  |
++-------------+------+
+empId is the column of unique values for this table.
+empId is a foreign key (reference column) to empId from the Employee table.
+Each row of this table contains the id of an employee and their respective bonus.
+
+ +

 

+ +

Write a solution to report the name and bonus amount of each employee with a bonus less than 1000.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Employee table:
++-------+--------+------------+--------+
+| empId | name   | supervisor | salary |
++-------+--------+------------+--------+
+| 3     | Brad   | null       | 4000   |
+| 1     | John   | 3          | 1000   |
+| 2     | Dan    | 3          | 2000   |
+| 4     | Thomas | 3          | 4000   |
++-------+--------+------------+--------+
+Bonus table:
++-------+-------+
+| empId | bonus |
++-------+-------+
+| 2     | 500   |
+| 4     | 2000  |
++-------+-------+
+Output: 
++------+-------+
+| name | bonus |
++------+-------+
+| Brad | null  |
+| John | null  |
+| Dan  | 500   |
++------+-------+
+
diff --git a/leetcode-cn/problem (English)/员工的直属部门(English) [primary-department-for-each-employee].html b/leetcode-cn/problem (English)/员工的直属部门(English) [primary-department-for-each-employee].html new file mode 100644 index 00000000..ebaee7ad --- /dev/null +++ b/leetcode-cn/problem (English)/员工的直属部门(English) [primary-department-for-each-employee].html @@ -0,0 +1,58 @@ +

Table: Employee

+ +
++---------------+---------+
+| Column Name   |  Type   |
++---------------+---------+
+| employee_id   | int     |
+| department_id | int     |
+| primary_flag  | varchar |
++---------------+---------+
+(employee_id, department_id) is the primary key (combination of columns with unique values) for this table.
+employee_id is the id of the employee.
+department_id is the id of the department to which the employee belongs.
+primary_flag is an ENUM (category) of type ('Y', 'N'). If the flag is 'Y', the department is the primary department for the employee. If the flag is 'N', the department is not the primary.
+
+ +

 

+ +

Employees can belong to multiple departments. When the employee joins other departments, they need to decide which department is their primary department. Note that when an employee belongs to only one department, their primary column is 'N'.

+ +

Write a solution to report all the employees with their primary department. For employees who belong to one department, report their only department.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Employee table:
++-------------+---------------+--------------+
+| employee_id | department_id | primary_flag |
++-------------+---------------+--------------+
+| 1           | 1             | N            |
+| 2           | 1             | Y            |
+| 2           | 2             | N            |
+| 3           | 3             | N            |
+| 4           | 2             | N            |
+| 4           | 3             | Y            |
+| 4           | 4             | N            |
++-------------+---------------+--------------+
+Output: 
++-------------+---------------+
+| employee_id | department_id |
++-------------+---------------+
+| 1           | 1             |
+| 2           | 1             |
+| 3           | 3             |
+| 4           | 3             |
++-------------+---------------+
+Explanation: 
+- The Primary department for employee 1 is 1.
+- The Primary department for employee 2 is 1.
+- The Primary department for employee 3 is 3.
+- The Primary department for employee 4 is 3.
+
diff --git a/leetcode-cn/problem (English)/填充缺失值(English) [fill-missing-data].html b/leetcode-cn/problem (English)/填充缺失值(English) [fill-missing-data].html new file mode 100644 index 00000000..cd833b19 --- /dev/null +++ b/leetcode-cn/problem (English)/填充缺失值(English) [fill-missing-data].html @@ -0,0 +1,37 @@ +
+DataFrame products
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| name        | object |
+| quantity    | int    |
+| price       | int    |
++-------------+--------+
+
+ +

Write a solution to fill in the missing value as 0 in the quantity column.

+ +

The result format is in the following example.

+ +

 

+
+Example 1:
+Input:+-----------------+----------+-------+
+| name            | quantity | price |
++-----------------+----------+-------+
+| Wristwatch      | None     | 135   |
+| WirelessEarbuds | None     | 821   |
+| GolfClubs       | 779      | 9319  |
+| Printer         | 849      | 3051  |
++-----------------+----------+-------+
+Output:
++-----------------+----------+-------+
+| name            | quantity | price |
++-----------------+----------+-------+
+| Wristwatch      | 0        | 135   |
+| WirelessEarbuds | 0        | 821   |
+| GolfClubs       | 779      | 9319  |
+| Printer         | 849      | 3051  |
++-----------------+----------+-------+
+Explanation: 
+The quantity for Wristwatch and WirelessEarbuds are filled by 0.
diff --git a/leetcode-cn/problem (English)/好友申请 II :谁有最多的好友(English) [friend-requests-ii-who-has-the-most-friends].html b/leetcode-cn/problem (English)/好友申请 II :谁有最多的好友(English) [friend-requests-ii-who-has-the-most-friends].html new file mode 100644 index 00000000..a35462e0 --- /dev/null +++ b/leetcode-cn/problem (English)/好友申请 II :谁有最多的好友(English) [friend-requests-ii-who-has-the-most-friends].html @@ -0,0 +1,48 @@ +

Table: RequestAccepted

+ +
++----------------+---------+
+| Column Name    | Type    |
++----------------+---------+
+| requester_id   | int     |
+| accepter_id    | int     |
+| accept_date    | date    |
++----------------+---------+
+(requester_id, accepter_id) is the primary key (combination of columns with unique values) for this table.
+This table contains the ID of the user who sent the request, the ID of the user who received the request, and the date when the request was accepted.
+
+ +

 

+ +

Write a solution to find the people who have the most friends and the most friends number.

+ +

The test cases are generated so that only one person has the most friends.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+RequestAccepted table:
++--------------+-------------+-------------+
+| requester_id | accepter_id | accept_date |
++--------------+-------------+-------------+
+| 1            | 2           | 2016/06/03  |
+| 1            | 3           | 2016/06/08  |
+| 2            | 3           | 2016/06/08  |
+| 3            | 4           | 2016/06/09  |
++--------------+-------------+-------------+
+Output: 
++----+-----+
+| id | num |
++----+-----+
+| 3  | 3   |
++----+-----+
+Explanation: 
+The person with id 3 is a friend of people 1, 2, and 4, so he has three friends in total, which is the most number than any others.
+
+ +

 

+

Follow up: In the real world, multiple people could have the same most number of friends. Could you find all these people in this case?

diff --git a/leetcode-cn/problem (English)/学生们参加各科测试的次数(English) [students-and-examinations].html b/leetcode-cn/problem (English)/学生们参加各科测试的次数(English) [students-and-examinations].html new file mode 100644 index 00000000..7c7e790a --- /dev/null +++ b/leetcode-cn/problem (English)/学生们参加各科测试的次数(English) [students-and-examinations].html @@ -0,0 +1,113 @@ +

Table: Students

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| student_id    | int     |
+| student_name  | varchar |
++---------------+---------+
+student_id is the primary key (column with unique values) for this table.
+Each row of this table contains the ID and the name of one student in the school.
+
+ +

 

+ +

Table: Subjects

+ +
++--------------+---------+
+| Column Name  | Type    |
++--------------+---------+
+| subject_name | varchar |
++--------------+---------+
+subject_name is the primary key (column with unique values) for this table.
+Each row of this table contains the name of one subject in the school.
+
+ +

 

+ +

Table: Examinations

+ +
++--------------+---------+
+| Column Name  | Type    |
++--------------+---------+
+| student_id   | int     |
+| subject_name | varchar |
++--------------+---------+
+There is no primary key (column with unique values) for this table. It may contain duplicates.
+Each student from the Students table takes every course from the Subjects table.
+Each row of this table indicates that a student with ID student_id attended the exam of subject_name.
+
+ +

 

+ +

Write a solution to find the number of times each student attended each exam.

+ +

Return the result table ordered by student_id and subject_name.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Students table:
++------------+--------------+
+| student_id | student_name |
++------------+--------------+
+| 1          | Alice        |
+| 2          | Bob          |
+| 13         | John         |
+| 6          | Alex         |
++------------+--------------+
+Subjects table:
++--------------+
+| subject_name |
++--------------+
+| Math         |
+| Physics      |
+| Programming  |
++--------------+
+Examinations table:
++------------+--------------+
+| student_id | subject_name |
++------------+--------------+
+| 1          | Math         |
+| 1          | Physics      |
+| 1          | Programming  |
+| 2          | Programming  |
+| 1          | Physics      |
+| 1          | Math         |
+| 13         | Math         |
+| 13         | Programming  |
+| 13         | Physics      |
+| 2          | Math         |
+| 1          | Math         |
++------------+--------------+
+Output: 
++------------+--------------+--------------+----------------+
+| student_id | student_name | subject_name | attended_exams |
++------------+--------------+--------------+----------------+
+| 1          | Alice        | Math         | 3              |
+| 1          | Alice        | Physics      | 2              |
+| 1          | Alice        | Programming  | 1              |
+| 2          | Bob          | Math         | 1              |
+| 2          | Bob          | Physics      | 0              |
+| 2          | Bob          | Programming  | 1              |
+| 6          | Alex         | Math         | 0              |
+| 6          | Alex         | Physics      | 0              |
+| 6          | Alex         | Programming  | 0              |
+| 13         | John         | Math         | 1              |
+| 13         | John         | Physics      | 1              |
+| 13         | John         | Programming  | 1              |
++------------+--------------+--------------+----------------+
+Explanation: 
+The result table should contain all students and all subjects.
+Alice attended the Math exam 3 times, the Physics exam 2 times, and the Programming exam 1 time.
+Bob attended the Math exam 1 time, the Programming exam 1 time, and did not attend the Physics exam.
+Alex did not attend any exams.
+John attended the Math exam 1 time, the Physics exam 1 time, and the Programming exam 1 time.
+
diff --git a/leetcode-cn/problem (English)/平均售价(English) [average-selling-price].html b/leetcode-cn/problem (English)/平均售价(English) [average-selling-price].html new file mode 100644 index 00000000..57b8d9b5 --- /dev/null +++ b/leetcode-cn/problem (English)/平均售价(English) [average-selling-price].html @@ -0,0 +1,75 @@ +

Table: Prices

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| product_id    | int     |
+| start_date    | date    |
+| end_date      | date    |
+| price         | int     |
++---------------+---------+
+(product_id, start_date, end_date) is the primary key (combination of columns with unique values) for this table.
+Each row of this table indicates the price of the product_id in the period from start_date to end_date.
+For each product_id there will be no two overlapping periods. That means there will be no two intersecting periods for the same product_id.
+
+ +

 

+ +

Table: UnitsSold

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| product_id    | int     |
+| purchase_date | date    |
+| units         | int     |
++---------------+---------+
+This table may contain duplicate rows.
+Each row of this table indicates the date, units, and product_id of each product sold. 
+
+ +

 

+ +

Write a solution to find the average selling price for each product. average_price should be rounded to 2 decimal places.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Prices table:
++------------+------------+------------+--------+
+| product_id | start_date | end_date   | price  |
++------------+------------+------------+--------+
+| 1          | 2019-02-17 | 2019-02-28 | 5      |
+| 1          | 2019-03-01 | 2019-03-22 | 20     |
+| 2          | 2019-02-01 | 2019-02-20 | 15     |
+| 2          | 2019-02-21 | 2019-03-31 | 30     |
++------------+------------+------------+--------+
+UnitsSold table:
++------------+---------------+-------+
+| product_id | purchase_date | units |
++------------+---------------+-------+
+| 1          | 2019-02-25    | 100   |
+| 1          | 2019-03-01    | 15    |
+| 2          | 2019-02-10    | 200   |
+| 2          | 2019-03-22    | 30    |
++------------+---------------+-------+
+Output: 
++------------+---------------+
+| product_id | average_price |
++------------+---------------+
+| 1          | 6.96          |
+| 2          | 16.96         |
++------------+---------------+
+Explanation: 
+Average selling price = Total Price of Product / Number of products sold.
+Average selling price for product 1 = ((100 * 5) + (15 * 20)) / 115 = 6.96
+Average selling price for product 2 = ((200 * 15) + (30 * 30)) / 230 = 16.96
+
diff --git a/leetcode-cn/problem (English)/弹珠游戏(English) [EXvqDp].html b/leetcode-cn/problem (English)/弹珠游戏(English) [EXvqDp].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/弹珠游戏(English) [EXvqDp].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/彩灯装饰记录 I(English) [cong-shang-dao-xia-da-yin-er-cha-shu-lcof].html b/leetcode-cn/problem (English)/彩灯装饰记录 I(English) [cong-shang-dao-xia-da-yin-er-cha-shu-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/彩灯装饰记录 I(English) [cong-shang-dao-xia-da-yin-er-cha-shu-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/彩灯装饰记录 II(English) [cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof].html b/leetcode-cn/problem (English)/彩灯装饰记录 II(English) [cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/彩灯装饰记录 II(English) [cong-shang-dao-xia-da-yin-er-cha-shu-ii-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/彩灯装饰记录 III(English) [cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof].html b/leetcode-cn/problem (English)/彩灯装饰记录 III(English) [cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/彩灯装饰记录 III(English) [cong-shang-dao-xia-da-yin-er-cha-shu-iii-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/心算挑战(English) [uOAnQW].html b/leetcode-cn/problem (English)/心算挑战(English) [uOAnQW].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/心算挑战(English) [uOAnQW].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/志愿者调配(English) [05ZEDJ].html b/leetcode-cn/problem (English)/志愿者调配(English) [05ZEDJ].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/志愿者调配(English) [05ZEDJ].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/快速公交(English) [meChtZ].html b/leetcode-cn/problem (English)/快速公交(English) [meChtZ].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/快速公交(English) [meChtZ].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/打地鼠(English) [ZbAuEH].html b/leetcode-cn/problem (English)/打地鼠(English) [ZbAuEH].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/打地鼠(English) [ZbAuEH].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/批量处理任务(English) [t3fKg1].html b/leetcode-cn/problem (English)/批量处理任务(English) [t3fKg1].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/批量处理任务(English) [t3fKg1].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/找到第 k 位数字(English) [shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof].html b/leetcode-cn/problem (English)/找到第 k 位数字(English) [shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/找到第 k 位数字(English) [shu-zi-xu-lie-zhong-mou-yi-wei-de-shu-zi-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/把字符串转换成整数 (atoi)(English) [ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof].html b/leetcode-cn/problem (English)/把字符串转换成整数 (atoi)(English) [ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/把字符串转换成整数 (atoi)(English) [ba-zi-fu-chuan-zhuan-huan-cheng-zheng-shu-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/报数(English) [da-yin-cong-1dao-zui-da-de-nwei-shu-lcof].html b/leetcode-cn/problem (English)/报数(English) [da-yin-cong-1dao-zui-da-de-nwei-shu-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/报数(English) [da-yin-cong-1dao-zui-da-de-nwei-shu-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/招式拆解 I(English) [zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof].html b/leetcode-cn/problem (English)/招式拆解 I(English) [zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/招式拆解 I(English) [zui-chang-bu-han-zhong-fu-zi-fu-de-zi-zi-fu-chuan-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/招式拆解 II(English) [di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof].html b/leetcode-cn/problem (English)/招式拆解 II(English) [di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/招式拆解 II(English) [di-yi-ge-zhi-chu-xian-yi-ci-de-zi-fu-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/拿硬币(English) [na-ying-bi].html b/leetcode-cn/problem (English)/拿硬币(English) [na-ying-bi].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/拿硬币(English) [na-ying-bi].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/指定日期的产品价格(English) [product-price-at-a-given-date].html b/leetcode-cn/problem (English)/指定日期的产品价格(English) [product-price-at-a-given-date].html new file mode 100644 index 00000000..248c6c82 --- /dev/null +++ b/leetcode-cn/problem (English)/指定日期的产品价格(English) [product-price-at-a-given-date].html @@ -0,0 +1,46 @@ +

Table: Products

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| product_id    | int     |
+| new_price     | int     |
+| change_date   | date    |
++---------------+---------+
+(product_id, change_date) is the primary key (combination of columns with unique values) of this table.
+Each row of this table indicates that the price of some product was changed to a new price at some date.
+ +

 

+ +

Write a solution to find the prices of all products on 2019-08-16. Assume the price of all products before any change is 10.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Products table:
++------------+-----------+-------------+
+| product_id | new_price | change_date |
++------------+-----------+-------------+
+| 1          | 20        | 2019-08-14  |
+| 2          | 50        | 2019-08-14  |
+| 1          | 30        | 2019-08-15  |
+| 1          | 35        | 2019-08-16  |
+| 2          | 65        | 2019-08-17  |
+| 3          | 20        | 2019-08-18  |
++------------+-----------+-------------+
+Output: 
++------------+-------+
+| product_id | price |
++------------+-------+
+| 2          | 50    |
+| 1          | 35    |
+| 3          | 10    |
++------------+-------+
+
diff --git a/leetcode-cn/problem (English)/按分类统计薪水(English) [count-salary-categories].html b/leetcode-cn/problem (English)/按分类统计薪水(English) [count-salary-categories].html new file mode 100644 index 00000000..1dd314d2 --- /dev/null +++ b/leetcode-cn/problem (English)/按分类统计薪水(English) [count-salary-categories].html @@ -0,0 +1,56 @@ +

Table: Accounts

+ +
++-------------+------+
+| Column Name | Type |
++-------------+------+
+| account_id  | int  |
+| income      | int  |
++-------------+------+
+account_id is the primary key (column with unique values) for this table.
+Each row contains information about the monthly income for one bank account.
+
+ +

 

+ +

Write a solution to calculate the number of bank accounts for each salary category. The salary categories are:

+ +
    +
  • "Low Salary": All the salaries strictly less than $20000.
  • +
  • "Average Salary": All the salaries in the inclusive range [$20000, $50000].
  • +
  • "High Salary": All the salaries strictly greater than $50000.
  • +
+ +

The result table must contain all three categories. If there are no accounts in a category, return 0.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Accounts table:
++------------+--------+
+| account_id | income |
++------------+--------+
+| 3          | 108939 |
+| 2          | 12747  |
+| 8          | 87709  |
+| 6          | 91796  |
++------------+--------+
+Output: 
++----------------+----------------+
+| category       | accounts_count |
++----------------+----------------+
+| Low Salary     | 1              |
+| Average Salary | 0              |
+| High Salary    | 3              |
++----------------+----------------+
+Explanation: 
+Low Salary: Account 2.
+Average Salary: No accounts.
+High Salary: Accounts 3, 6, and 8.
+
diff --git a/leetcode-cn/problem (English)/按字典序排列最小的等效字符串(English) [lexicographically-smallest-equivalent-string].html b/leetcode-cn/problem (English)/按字典序排列最小的等效字符串(English) [lexicographically-smallest-equivalent-string].html new file mode 100644 index 00000000..b9c2559a --- /dev/null +++ b/leetcode-cn/problem (English)/按字典序排列最小的等效字符串(English) [lexicographically-smallest-equivalent-string].html @@ -0,0 +1,56 @@ +

You are given two strings of the same length s1 and s2 and a string baseStr.

+ +

We say s1[i] and s2[i] are equivalent characters.

+ +
    +
  • For example, if s1 = "abc" and s2 = "cde", then we have 'a' == 'c', 'b' == 'd', and 'c' == 'e'.
  • +
+ +

Equivalent characters follow the usual rules of any equivalence relation:

+ +
    +
  • Reflexivity: 'a' == 'a'.
  • +
  • Symmetry: 'a' == 'b' implies 'b' == 'a'.
  • +
  • Transitivity: 'a' == 'b' and 'b' == 'c' implies 'a' == 'c'.
  • +
+ +

For example, given the equivalency information from s1 = "abc" and s2 = "cde", "acd" and "aab" are equivalent strings of baseStr = "eed", and "aab" is the lexicographically smallest equivalent string of baseStr.

+ +

Return the lexicographically smallest equivalent string of baseStr by using the equivalency information from s1 and s2.

+ +

 

+

Example 1:

+ +
+Input: s1 = "parker", s2 = "morris", baseStr = "parser"
+Output: "makkek"
+Explanation: Based on the equivalency information in s1 and s2, we can group their characters as [m,p], [a,o], [k,r,s], [e,i].
+The characters in each group are equivalent and sorted in lexicographical order.
+So the answer is "makkek".
+
+ +

Example 2:

+ +
+Input: s1 = "hello", s2 = "world", baseStr = "hold"
+Output: "hdld"
+Explanation: Based on the equivalency information in s1 and s2, we can group their characters as [h,w], [d,e,o], [l,r].
+So only the second letter 'o' in baseStr is changed to 'd', the answer is "hdld".
+
+ +

Example 3:

+ +
+Input: s1 = "leetcode", s2 = "programs", baseStr = "sourcecode"
+Output: "aauaaaaada"
+Explanation: We group the equivalent characters in s1 and s2 as [a,o,e,r,s,c], [l,p], [g,t] and [d,m], thus all letters in baseStr except 'u' and 'd' are transformed to 'a', the answer is "aauaaaaada".
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s1.length, s2.length, baseStr <= 1000
  • +
  • s1.length == s2.length
  • +
  • s1, s2, and baseStr consist of lowercase English letters.
  • +
diff --git a/leetcode-cn/problem (English)/按规则计算统计结果(English) [gou-jian-cheng-ji-shu-zu-lcof].html b/leetcode-cn/problem (English)/按规则计算统计结果(English) [gou-jian-cheng-ji-shu-zu-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/按规则计算统计结果(English) [gou-jian-cheng-ji-shu-zu-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/探险营地(English) [0Zeoeg].html b/leetcode-cn/problem (English)/探险营地(English) [0Zeoeg].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/探险营地(English) [0Zeoeg].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/提取咒文(English) [kjpLFZ].html b/leetcode-cn/problem (English)/提取咒文(English) [kjpLFZ].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/提取咒文(English) [kjpLFZ].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/搭桥过河(English) [NfY1m5].html b/leetcode-cn/problem (English)/搭桥过河(English) [NfY1m5].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/搭桥过河(English) [NfY1m5].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/改变数据类型(English) [change-data-type].html b/leetcode-cn/problem (English)/改变数据类型(English) [change-data-type].html new file mode 100644 index 00000000..b390d917 --- /dev/null +++ b/leetcode-cn/problem (English)/改变数据类型(English) [change-data-type].html @@ -0,0 +1,38 @@ +
+DataFrame students
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| student_id  | int    |
+| name        | object |
+| age         | int    |
+| grade       | float  |
++-------------+--------+
+
+ +

Write a solution to correct the errors:

+ +

The grade column is stored as floats, convert it to integers.

+ +

The result format is in the following example.

+ +

 

+
+Example 1:
+Input:
+DataFrame students:
++------------+------+-----+-------+
+| student_id | name | age | grade |
++------------+------+-----+-------+
+| 1          | Ava  | 6   | 73.0  |
+| 2          | Kate | 15  | 87.0  |
++------------+------+-----+-------+
+Output:
++------------+------+-----+-------+
+| student_id | name | age | grade |
++------------+------+-----+-------+
+| 1          | Ava  | 6   | 73    |
+| 2          | Kate | 15  | 87    |
++------------+------+-----+-------+
+Explanation: 
+The data types of the column grade is converted to int.
diff --git a/leetcode-cn/problem (English)/数字 1 的个数(English) [1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof].html b/leetcode-cn/problem (English)/数字 1 的个数(English) [1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/数字 1 的个数(English) [1nzheng-shu-zhong-1chu-xian-de-ci-shu-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/数字游戏(English) [5TxKeK].html b/leetcode-cn/problem (English)/数字游戏(English) [5TxKeK].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/数字游戏(English) [5TxKeK].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/数据选取(English) [select-data].html b/leetcode-cn/problem (English)/数据选取(English) [select-data].html new file mode 100644 index 00000000..d7f007c0 --- /dev/null +++ b/leetcode-cn/problem (English)/数据选取(English) [select-data].html @@ -0,0 +1,36 @@ +
+DataFrame students
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| student_id  | int    |
+| name        | object |
+| age         | int    |
++-------------+--------+
+
+
+ +

Write a solution to select the name and age of the student with student_id = 101.

+ +

The result format is in the following example.

+ +

 

+
+Example 1:
+Input:
++------------+---------+-----+
+| student_id | name    | age |
++------------+---------+-----+
+| 101        | Ulysses | 13  |
+| 53         | William | 10  |
+| 128        | Henry   | 6   |
+| 3          | Henry   | 11  |
++------------+---------+-----+
+Output:
++---------+-----+
+| name    | age | 
++---------+-----+
+| Ulysses | 13  |
++---------+-----+
+Explanation:
+Student Ulysses has student_id = 101, we select the name and age.
diff --git a/leetcode-cn/problem (English)/数据重塑:透视(English) [reshape-data-pivot].html b/leetcode-cn/problem (English)/数据重塑:透视(English) [reshape-data-pivot].html new file mode 100644 index 00000000..fd2133e9 --- /dev/null +++ b/leetcode-cn/problem (English)/数据重塑:透视(English) [reshape-data-pivot].html @@ -0,0 +1,45 @@ +
+DataFrame weather
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| city        | object |
+| month       | object |
+| temperature | int    |
++-------------+--------+
+
+ +

Write a solution to pivot the data so that each row represents temperatures for a specific month, and each city is a separate column.

+ +

The result format is in the following example.

+ +

 

+
+Example 1:
+Input:
++--------------+----------+-------------+
+| city         | month    | temperature |
++--------------+----------+-------------+
+| Jacksonville | January  | 13          |
+| Jacksonville | February | 23          |
+| Jacksonville | March    | 38          |
+| Jacksonville | April    | 5           |
+| Jacksonville | May      | 34          |
+| ElPaso       | January  | 20          |
+| ElPaso       | February | 6           |
+| ElPaso       | March    | 26          |
+| ElPaso       | April    | 2           |
+| ElPaso       | May      | 43          |
++--------------+----------+-------------+
+Output:
++----------+--------+--------------+
+| month    | ElPaso | Jacksonville |
++----------+--------+--------------+
+| April    | 2      | 5            |
+| February | 6      | 23           |
+| January  | 20     | 13           |
+| March    | 26     | 38           |
+| May      | 43     | 34           |
++----------+--------+--------------+
+Explanation:
+The table is pivoted, each column represents a city, and each row represents a specific month.
diff --git a/leetcode-cn/problem (English)/文物朝代判断(English) [bu-ke-pai-zhong-de-shun-zi-lcof].html b/leetcode-cn/problem (English)/文物朝代判断(English) [bu-ke-pai-zhong-de-shun-zi-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/文物朝代判断(English) [bu-ke-pai-zhong-de-shun-zi-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/斐波那契数(English) [fei-bo-na-qi-shu-lie-lcof].html b/leetcode-cn/problem (English)/斐波那契数(English) [fei-bo-na-qi-shu-lie-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/斐波那契数(English) [fei-bo-na-qi-shu-lie-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/方法链(English) [method-chaining].html b/leetcode-cn/problem (English)/方法链(English) [method-chaining].html new file mode 100644 index 00000000..22d41aac --- /dev/null +++ b/leetcode-cn/problem (English)/方法链(English) [method-chaining].html @@ -0,0 +1,52 @@ +
+DataFrame animals
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| name        | object |
+| species     | object |
+| age         | int    |
+| weight      | int    |
++-------------+--------+
+
+ +

Write a solution to list the names of animals that weigh strictly more than 100 kilograms.

+ +

Return the animals sorted by weight in descending order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+DataFrame animals:
++----------+---------+-----+--------+
+| name     | species | age | weight |
++----------+---------+-----+--------+
+| Tatiana  | Snake   | 98  | 464    |
+| Khaled   | Giraffe | 50  | 41     |
+| Alex     | Leopard | 6   | 328    |
+| Jonathan | Monkey  | 45  | 463    |
+| Stefan   | Bear    | 100 | 50     |
+| Tommy    | Panda   | 26  | 349    |
++----------+---------+-----+--------+
+Output: 
++----------+
+| name     |
++----------+
+| Tatiana  |
+| Jonathan |
+| Tommy    |
+| Alex     |
++----------+
+Explanation: 
+All animals weighing more than 100 should be included in the results table.
+Tatiana's weight is 464, Jonathan's weight is 463, Tommy's weight is 349, and Alex's weight is 328.
+The results should be sorted in descending order of weight.
+ +

 

+

In Pandas, method chaining enables us to perform operations on a DataFrame without breaking up each operation into a separate line or creating multiple temporary variables. 

+ +

Can you complete this task in just one line of code using method chaining?

diff --git a/leetcode-cn/problem (English)/无人机方阵(English) [0jQkd0].html b/leetcode-cn/problem (English)/无人机方阵(English) [0jQkd0].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/无人机方阵(English) [0jQkd0].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/无效的推文(English) [invalid-tweets].html b/leetcode-cn/problem (English)/无效的推文(English) [invalid-tweets].html new file mode 100644 index 00000000..fe85b029 --- /dev/null +++ b/leetcode-cn/problem (English)/无效的推文(English) [invalid-tweets].html @@ -0,0 +1,43 @@ +

Table: Tweets

+ +
++----------------+---------+
+| Column Name    | Type    |
++----------------+---------+
+| tweet_id       | int     |
+| content        | varchar |
++----------------+---------+
+tweet_id is the primary key (column with unique values) for this table.
+This table contains all the tweets in a social media app.
+
+ +

 

+ +

Write a solution to find the IDs of the invalid tweets. The tweet is invalid if the number of characters used in the content of the tweet is strictly greater than 15.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Tweets table:
++----------+----------------------------------+
+| tweet_id | content                          |
++----------+----------------------------------+
+| 1        | Vote for Biden                   |
+| 2        | Let us make America great again! |
++----------+----------------------------------+
+Output: 
++----------+
+| tweet_id |
++----------+
+| 2        |
++----------+
+Explanation: 
+Tweet 1 has length = 14. It is a valid tweet.
+Tweet 2 has length = 32. It is an invalid tweet.
+
diff --git a/leetcode-cn/problem (English)/无限棋局(English) [fsa7oZ].html b/leetcode-cn/problem (English)/无限棋局(English) [fsa7oZ].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/无限棋局(English) [fsa7oZ].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/早餐组合(English) [2vYnGI].html b/leetcode-cn/problem (English)/早餐组合(English) [2vYnGI].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/早餐组合(English) [2vYnGI].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/显示前三行(English) [display-the-first-three-rows].html b/leetcode-cn/problem (English)/显示前三行(English) [display-the-first-three-rows].html new file mode 100644 index 00000000..32ad47c8 --- /dev/null +++ b/leetcode-cn/problem (English)/显示前三行(English) [display-the-first-three-rows].html @@ -0,0 +1,40 @@ +
+DataFrame: employees
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| employee_id | int    |
+| name        | object |
+| department  | object |
+| salary      | int    |
++-------------+--------+
+
+ +

Write a solution to display the first 3 rows of this DataFrame.

+ +

 

+

Example 1:

+ +
+Input:
+DataFrame employees
++-------------+-----------+-----------------------+--------+
+| employee_id | name      | department            | salary |
++-------------+-----------+-----------------------+--------+
+| 3           | Bob       | Operations            | 48675  |
+| 90          | Alice     | Sales                 | 11096  |
+| 9           | Tatiana   | Engineering           | 33805  |
+| 60          | Annabelle | InformationTechnology | 37678  |
+| 49          | Jonathan  | HumanResources        | 23793  |
+| 43          | Khaled    | Administration        | 40454  |
++-------------+-----------+-----------------------+--------+
+Output:
++-------------+---------+-------------+--------+
+| employee_id | name    | department  | salary |
++-------------+---------+-------------+--------+
+| 3           | Bob     | Operations  | 48675  |
+| 90          | Alice   | Sales       | 11096  |
+| 9           | Tatiana | Engineering | 33805  |
++-------------+---------+-------------+--------+
+Explanation: 
+Only the first 3 rows are displayed.
diff --git a/leetcode-cn/problem (English)/最后一个能进入巴士的人(English) [last-person-to-fit-in-the-bus].html b/leetcode-cn/problem (English)/最后一个能进入巴士的人(English) [last-person-to-fit-in-the-bus].html new file mode 100644 index 00000000..7106945a --- /dev/null +++ b/leetcode-cn/problem (English)/最后一个能进入巴士的人(English) [last-person-to-fit-in-the-bus].html @@ -0,0 +1,60 @@ +

Table: Queue

+ +
++-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| person_id   | int     |
+| person_name | varchar |
+| weight      | int     |
+| turn        | int     |
++-------------+---------+
+person_id column contains unique values.
+This table has the information about all people waiting for a bus.
+The person_id and turn columns will contain all numbers from 1 to n, where n is the number of rows in the table.
+turn determines the order of which the people will board the bus, where turn=1 denotes the first person to board and turn=n denotes the last person to board.
+weight is the weight of the person in kilograms.
+
+ +

 

+ +

There is a queue of people waiting to board a bus. However, the bus has a weight limit of 1000 kilograms, so there may be some people who cannot board.

+ +

Write a solution to find the person_name of the last person that can fit on the bus without exceeding the weight limit. The test cases are generated such that the first person does not exceed the weight limit.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Queue table:
++-----------+-------------+--------+------+
+| person_id | person_name | weight | turn |
++-----------+-------------+--------+------+
+| 5         | Alice       | 250    | 1    |
+| 4         | Bob         | 175    | 5    |
+| 3         | Alex        | 350    | 2    |
+| 6         | John Cena   | 400    | 3    |
+| 1         | Winston     | 500    | 6    |
+| 2         | Marie       | 200    | 4    |
++-----------+-------------+--------+------+
+Output: 
++-------------+
+| person_name |
++-------------+
+| John Cena   |
++-------------+
+Explanation: The folowing table is ordered by the turn for simplicity.
++------+----+-----------+--------+--------------+
+| Turn | ID | Name      | Weight | Total Weight |
++------+----+-----------+--------+--------------+
+| 1    | 5  | Alice     | 250    | 250          |
+| 2    | 3  | Alex      | 350    | 600          |
+| 3    | 6  | John Cena | 400    | 1000         | (last person to board)
+| 4    | 2  | Marie     | 200    | 1200         | (cannot board)
+| 5    | 4  | Bob       | 175    | ___          |
+| 6    | 1  | Winston   | 500    | ___          |
++------+----+-----------+--------+--------------+
+
diff --git a/leetcode-cn/problem (English)/最多牌组数(English) [Up5XYM].html b/leetcode-cn/problem (English)/最多牌组数(English) [Up5XYM].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/最多牌组数(English) [Up5XYM].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/最小展台数量(English) [600YaG].html b/leetcode-cn/problem (English)/最小展台数量(English) [600YaG].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/最小展台数量(English) [600YaG].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/最小栈(English) [bao-han-minhan-shu-de-zhan-lcof].html b/leetcode-cn/problem (English)/最小栈(English) [bao-han-minhan-shu-de-zhan-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/最小栈(English) [bao-han-minhan-shu-de-zhan-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/最小矩形面积(English) [zui-xiao-ju-xing-mian-ji].html b/leetcode-cn/problem (English)/最小矩形面积(English) [zui-xiao-ju-xing-mian-ji].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/最小矩形面积(English) [zui-xiao-ju-xing-mian-ji].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/最小跳跃次数(English) [zui-xiao-tiao-yue-ci-shu].html b/leetcode-cn/problem (English)/最小跳跃次数(English) [zui-xiao-tiao-yue-ci-shu].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/最小跳跃次数(English) [zui-xiao-tiao-yue-ci-shu].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/最强祝福力场(English) [xepqZ5].html b/leetcode-cn/problem (English)/最强祝福力场(English) [xepqZ5].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/最强祝福力场(English) [xepqZ5].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/期望个数统计(English) [qi-wang-ge-shu-tong-ji].html b/leetcode-cn/problem (English)/期望个数统计(English) [qi-wang-ge-shu-tong-ji].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/期望个数统计(English) [qi-wang-ge-shu-tong-ji].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/查找拥有有效邮箱的用户(English) [find-users-with-valid-e-mails].html b/leetcode-cn/problem (English)/查找拥有有效邮箱的用户(English) [find-users-with-valid-e-mails].html new file mode 100644 index 00000000..8775cca4 --- /dev/null +++ b/leetcode-cn/problem (English)/查找拥有有效邮箱的用户(English) [find-users-with-valid-e-mails].html @@ -0,0 +1,60 @@ +

Table: Users

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| user_id       | int     |
+| name          | varchar |
+| mail          | varchar |
++---------------+---------+
+user_id is the primary key (column with unique values) for this table.
+This table contains information of the users signed up in a website. Some e-mails are invalid.
+
+ +

 

+ +

Write a solution to find the users who have valid emails.

+ +

A valid e-mail has a prefix name and a domain where:

+ +
    +
  • The prefix name is a string that may contain letters (upper or lower case), digits, underscore '_', period '.', and/or dash '-'. The prefix name must start with a letter.
  • +
  • The domain is '@leetcode.com'.
  • +
+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Users table:
++---------+-----------+-------------------------+
+| user_id | name      | mail                    |
++---------+-----------+-------------------------+
+| 1       | Winston   | winston@leetcode.com    |
+| 2       | Jonathan  | jonathanisgreat         |
+| 3       | Annabelle | bella-@leetcode.com     |
+| 4       | Sally     | sally.come@leetcode.com |
+| 5       | Marwan    | quarz#2020@leetcode.com |
+| 6       | David     | david69@gmail.com       |
+| 7       | Shapiro   | .shapo@leetcode.com     |
++---------+-----------+-------------------------+
+Output: 
++---------+-----------+-------------------------+
+| user_id | name      | mail                    |
++---------+-----------+-------------------------+
+| 1       | Winston   | winston@leetcode.com    |
+| 3       | Annabelle | bella-@leetcode.com     |
+| 4       | Sally     | sally.come@leetcode.com |
++---------+-----------+-------------------------+
+Explanation: 
+The mail of user 2 does not have a domain.
+The mail of user 5 has the # sign which is not allowed.
+The mail of user 6 does not have the leetcode domain.
+The mail of user 7 starts with a period.
+
diff --git a/leetcode-cn/problem (English)/查询结果的质量和占比(English) [queries-quality-and-percentage].html b/leetcode-cn/problem (English)/查询结果的质量和占比(English) [queries-quality-and-percentage].html new file mode 100644 index 00000000..b7343c6f --- /dev/null +++ b/leetcode-cn/problem (English)/查询结果的质量和占比(English) [queries-quality-and-percentage].html @@ -0,0 +1,69 @@ +

Table: Queries

+ +
++-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| query_name  | varchar |
+| result      | varchar |
+| position    | int     |
+| rating      | int     |
++-------------+---------+
+This table may have duplicate rows.
+This table contains information collected from some queries on a database.
+The position column has a value from 1 to 500.
+The rating column has a value from 1 to 5. Query with rating less than 3 is a poor query.
+
+ +

 

+ +

We define query quality as:

+ +
+

The average of the ratio between query rating and its position.

+
+ +

We also define poor query percentage as:

+ +
+

The percentage of all queries with rating less than 3.

+
+ +

Write a solution to find each query_name, the quality and poor_query_percentage.

+ +

Both quality and poor_query_percentage should be rounded to 2 decimal places.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Queries table:
++------------+-------------------+----------+--------+
+| query_name | result            | position | rating |
++------------+-------------------+----------+--------+
+| Dog        | Golden Retriever  | 1        | 5      |
+| Dog        | German Shepherd   | 2        | 5      |
+| Dog        | Mule              | 200      | 1      |
+| Cat        | Shirazi           | 5        | 2      |
+| Cat        | Siamese           | 3        | 3      |
+| Cat        | Sphynx            | 7        | 4      |
++------------+-------------------+----------+--------+
+Output: 
++------------+---------+-----------------------+
+| query_name | quality | poor_query_percentage |
++------------+---------+-----------------------+
+| Dog        | 2.50    | 33.33                 |
+| Cat        | 0.66    | 33.33                 |
++------------+---------+-----------------------+
+Explanation: 
+Dog queries quality is ((5 / 1) + (5 / 2) + (1 / 200)) / 3 = 2.50
+Dog queries poor_ query_percentage is (1 / 3) * 100 = 33.33
+
+Cat queries quality equals ((2 / 5) + (3 / 3) + (4 / 7)) / 3 = 0.66
+Cat queries poor_ query_percentage is (1 / 3) * 100 = 33.33
+
diff --git a/leetcode-cn/problem (English)/模糊搜索验证(English) [zheng-ze-biao-da-shi-pi-pei-lcof].html b/leetcode-cn/problem (English)/模糊搜索验证(English) [zheng-ze-biao-da-shi-pi-pei-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/模糊搜索验证(English) [zheng-ze-biao-da-shi-pi-pei-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/每位教师所教授的科目种类的数量(English) [number-of-unique-subjects-taught-by-each-teacher].html b/leetcode-cn/problem (English)/每位教师所教授的科目种类的数量(English) [number-of-unique-subjects-taught-by-each-teacher].html new file mode 100644 index 00000000..9940a40a --- /dev/null +++ b/leetcode-cn/problem (English)/每位教师所教授的科目种类的数量(English) [number-of-unique-subjects-taught-by-each-teacher].html @@ -0,0 +1,56 @@ +

Table: Teacher

+ +
++-------------+------+
+| Column Name | Type |
++-------------+------+
+| teacher_id  | int  |
+| subject_id  | int  |
+| dept_id     | int  |
++-------------+------+
+(subject_id, dept_id) is the primary key (combinations of columns with unique values) of this table.
+Each row in this table indicates that the teacher with teacher_id teaches the subject subject_id in the department dept_id.
+
+ +

 

+ +

Write a solution to calculate the number of unique subjects each teacher teaches in the university.

+ +

Return the result table in any order.

+ +

The result format is shown in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Teacher table:
++------------+------------+---------+
+| teacher_id | subject_id | dept_id |
++------------+------------+---------+
+| 1          | 2          | 3       |
+| 1          | 2          | 4       |
+| 1          | 3          | 3       |
+| 2          | 1          | 1       |
+| 2          | 2          | 1       |
+| 2          | 3          | 1       |
+| 2          | 4          | 1       |
++------------+------------+---------+
+Output:  
++------------+-----+
+| teacher_id | cnt |
++------------+-----+
+| 1          | 2   |
+| 2          | 4   |
++------------+-----+
+Explanation: 
+Teacher 1:
+  - They teach subject 2 in departments 3 and 4.
+  - They teach subject 3 in department 3.
+Teacher 2:
+  - They teach subject 1 in department 1.
+  - They teach subject 2 in department 1.
+  - They teach subject 3 in department 1.
+  - They teach subject 4 in department 1.
+
diff --git a/leetcode-cn/problem (English)/每位经理的下属员工数量(English) [the-number-of-employees-which-report-to-each-employee].html b/leetcode-cn/problem (English)/每位经理的下属员工数量(English) [the-number-of-employees-which-report-to-each-employee].html new file mode 100644 index 00000000..b6575fd7 --- /dev/null +++ b/leetcode-cn/problem (English)/每位经理的下属员工数量(English) [the-number-of-employees-which-report-to-each-employee].html @@ -0,0 +1,47 @@ +

Table: Employees

+ +
++-------------+----------+
+| Column Name | Type     |
++-------------+----------+
+| employee_id | int      |
+| name        | varchar  |
+| reports_to  | int      |
+| age         | int      |
++-------------+----------+
+employee_id is the column with unique values for this table.
+This table contains information about the employees and the id of the manager they report to. Some employees do not report to anyone (reports_to is null). 
+
+ +

 

+ +

For this problem, we will consider a manager an employee who has at least 1 other employee reporting to them.

+ +

Write a solution to report the ids and the names of all managers, the number of employees who report directly to them, and the average age of the reports rounded to the nearest integer.

+ +

Return the result table ordered by employee_id.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Employees table:
++-------------+---------+------------+-----+
+| employee_id | name    | reports_to | age |
++-------------+---------+------------+-----+
+| 9           | Hercy   | null       | 43  |
+| 6           | Alice   | 9          | 41  |
+| 4           | Bob     | 9          | 36  |
+| 2           | Winston | null       | 37  |
++-------------+---------+------------+-----+
+Output: 
++-------------+-------+---------------+-------------+
+| employee_id | name  | reports_count | average_age |
++-------------+-------+---------------+-------------+
+| 9           | Hercy | 2             | 39          |
++-------------+-------+---------------+-------------+
+Explanation: Hercy has 2 people report directly to him, Alice and Bob. Their average age is (41+36)/2 = 38.5, which is 39 after rounding it to the nearest integer.
+
diff --git a/leetcode-cn/problem (English)/每台机器的进程平均运行时间(English) [average-time-of-process-per-machine].html b/leetcode-cn/problem (English)/每台机器的进程平均运行时间(English) [average-time-of-process-per-machine].html new file mode 100644 index 00000000..cabce950 --- /dev/null +++ b/leetcode-cn/problem (English)/每台机器的进程平均运行时间(English) [average-time-of-process-per-machine].html @@ -0,0 +1,68 @@ +

Table: Activity

+ +
++----------------+---------+
+| Column Name    | Type    |
++----------------+---------+
+| machine_id     | int     |
+| process_id     | int     |
+| activity_type  | enum    |
+| timestamp      | float   |
++----------------+---------+
+The table shows the user activities for a factory website.
+(machine_id, process_id, activity_type) is the primary key (combination of columns with unique values) of this table.
+machine_id is the ID of a machine.
+process_id is the ID of a process running on the machine with ID machine_id.
+activity_type is an ENUM (category) of type ('start', 'end').
+timestamp is a float representing the current time in seconds.
+'start' means the machine starts the process at the given timestamp and 'end' means the machine ends the process at the given timestamp.
+The 'start' timestamp will always be before the 'end' timestamp for every (machine_id, process_id) pair.
+ +

 

+ +

There is a factory website that has several machines each running the same number of processes. Write a solution to find the average time each machine takes to complete a process.

+ +

The time to complete a process is the 'end' timestamp minus the 'start' timestamp. The average time is calculated by the total time to complete every process on the machine divided by the number of processes that were run.

+ +

The resulting table should have the machine_id along with the average time as processing_time, which should be rounded to 3 decimal places.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Activity table:
++------------+------------+---------------+-----------+
+| machine_id | process_id | activity_type | timestamp |
++------------+------------+---------------+-----------+
+| 0          | 0          | start         | 0.712     |
+| 0          | 0          | end           | 1.520     |
+| 0          | 1          | start         | 3.140     |
+| 0          | 1          | end           | 4.120     |
+| 1          | 0          | start         | 0.550     |
+| 1          | 0          | end           | 1.550     |
+| 1          | 1          | start         | 0.430     |
+| 1          | 1          | end           | 1.420     |
+| 2          | 0          | start         | 4.100     |
+| 2          | 0          | end           | 4.512     |
+| 2          | 1          | start         | 2.500     |
+| 2          | 1          | end           | 5.000     |
++------------+------------+---------------+-----------+
+Output: 
++------------+-----------------+
+| machine_id | processing_time |
++------------+-----------------+
+| 0          | 0.894           |
+| 1          | 0.995           |
+| 2          | 1.456           |
++------------+-----------------+
+Explanation: 
+There are 3 machines running 2 processes each.
+Machine 0's average time is ((1.520 - 0.712) + (4.120 - 3.140)) / 2 = 0.894
+Machine 1's average time is ((1.550 - 0.550) + (1.420 - 0.430)) / 2 = 0.995
+Machine 2's average time is ((4.512 - 4.100) + (5.000 - 2.500)) / 2 = 1.456
+
diff --git a/leetcode-cn/problem (English)/每月交易 I(English) [monthly-transactions-i].html b/leetcode-cn/problem (English)/每月交易 I(English) [monthly-transactions-i].html new file mode 100644 index 00000000..2d146def --- /dev/null +++ b/leetcode-cn/problem (English)/每月交易 I(English) [monthly-transactions-i].html @@ -0,0 +1,48 @@ +

Table: Transactions

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| id            | int     |
+| country       | varchar |
+| state         | enum    |
+| amount        | int     |
+| trans_date    | date    |
++---------------+---------+
+id is the primary key of this table.
+The table has information about incoming transactions.
+The state column is an enum of type ["approved", "declined"].
+
+ +

 

+ +

Write an SQL query to find for each month and country, the number of transactions and their total amount, the number of approved transactions and their total amount.

+ +

Return the result table in any order.

+ +

The query result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Transactions table:
++------+---------+----------+--------+------------+
+| id   | country | state    | amount | trans_date |
++------+---------+----------+--------+------------+
+| 121  | US      | approved | 1000   | 2018-12-18 |
+| 122  | US      | declined | 2000   | 2018-12-19 |
+| 123  | US      | approved | 2000   | 2019-01-01 |
+| 124  | DE      | approved | 2000   | 2019-01-07 |
++------+---------+----------+--------+------------+
+Output: 
++----------+---------+-------------+----------------+--------------------+-----------------------+
+| month    | country | trans_count | approved_count | trans_total_amount | approved_total_amount |
++----------+---------+-------------+----------------+--------------------+-----------------------+
+| 2018-12  | US      | 2           | 1              | 3000               | 1000                  |
+| 2019-01  | US      | 1           | 1              | 2000               | 2000                  |
+| 2019-01  | DE      | 1           | 1              | 2000               | 2000                  |
++----------+---------+-------------+----------------+--------------------+-----------------------+
+
diff --git a/leetcode-cn/problem (English)/气温变化趋势(English) [6CE719].html b/leetcode-cn/problem (English)/气温变化趋势(English) [6CE719].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/气温变化趋势(English) [6CE719].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/沙地治理(English) [XxZZjK].html b/leetcode-cn/problem (English)/沙地治理(English) [XxZZjK].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/沙地治理(English) [XxZZjK].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/游乐园的游览计划(English) [you-le-yuan-de-you-lan-ji-hua].html b/leetcode-cn/problem (English)/游乐园的游览计划(English) [you-le-yuan-de-you-lan-ji-hua].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/游乐园的游览计划(English) [you-le-yuan-de-you-lan-ji-hua].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/游乐园的迷宫(English) [you-le-yuan-de-mi-gong].html b/leetcode-cn/problem (English)/游乐园的迷宫(English) [you-le-yuan-de-mi-gong].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/游乐园的迷宫(English) [you-le-yuan-de-mi-gong].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/游戏玩法分析 IV(English) [game-play-analysis-iv].html b/leetcode-cn/problem (English)/游戏玩法分析 IV(English) [game-play-analysis-iv].html new file mode 100644 index 00000000..f67c2535 --- /dev/null +++ b/leetcode-cn/problem (English)/游戏玩法分析 IV(English) [game-play-analysis-iv].html @@ -0,0 +1,46 @@ +

Table: Activity

+ +
++--------------+---------+
+| Column Name  | Type    |
++--------------+---------+
+| player_id    | int     |
+| device_id    | int     |
+| event_date   | date    |
+| games_played | int     |
++--------------+---------+
+(player_id, event_date) is the primary key (combination of columns with unique values) of this table.
+This table shows the activity of players of some games.
+Each row is a record of a player who logged in and played a number of games (possibly 0) before logging out on someday using some device.
+
+ +

 

+ +

Write a solution to report the fraction of players that logged in again on the day after the day they first logged in, rounded to 2 decimal places. In other words, you need to count the number of players that logged in for at least two consecutive days starting from their first login date, then divide that number by the total number of players.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Activity table:
++-----------+-----------+------------+--------------+
+| player_id | device_id | event_date | games_played |
++-----------+-----------+------------+--------------+
+| 1         | 2         | 2016-03-01 | 5            |
+| 1         | 2         | 2016-03-02 | 6            |
+| 2         | 3         | 2017-06-25 | 1            |
+| 3         | 1         | 2016-03-02 | 0            |
+| 3         | 4         | 2018-07-03 | 5            |
++-----------+-----------+------------+--------------+
+Output: 
++-----------+
+| fraction  |
++-----------+
+| 0.33      |
++-----------+
+Explanation: 
+Only the player with id 1 logged back in after the first day he had logged in so the answer is 1/3 = 0.33
+
diff --git a/leetcode-cn/problem (English)/点名(English) [que-shi-de-shu-zi-lcof].html b/leetcode-cn/problem (English)/点名(English) [que-shi-de-shu-zi-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/点名(English) [que-shi-de-shu-zi-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/烹饪料理(English) [UEcfPD].html b/leetcode-cn/problem (English)/烹饪料理(English) [UEcfPD].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/烹饪料理(English) [UEcfPD].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/玩具套圈(English) [vFjcfV].html b/leetcode-cn/problem (English)/玩具套圈(English) [vFjcfV].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/玩具套圈(English) [vFjcfV].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/环形闯关游戏(English) [K8GULz].html b/leetcode-cn/problem (English)/环形闯关游戏(English) [K8GULz].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/环形闯关游戏(English) [K8GULz].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/珠宝的最高价值(English) [li-wu-de-zui-da-jie-zhi-lcof].html b/leetcode-cn/problem (English)/珠宝的最高价值(English) [li-wu-de-zui-da-jie-zhi-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/珠宝的最高价值(English) [li-wu-de-zui-da-jie-zhi-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/生物进化录(English) [qoQAMX].html b/leetcode-cn/problem (English)/生物进化录(English) [qoQAMX].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/生物进化录(English) [qoQAMX].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/电动车游城市(English) [DFPeFJ].html b/leetcode-cn/problem (English)/电动车游城市(English) [DFPeFJ].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/电动车游城市(English) [DFPeFJ].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/电影评分(English) [movie-rating].html b/leetcode-cn/problem (English)/电影评分(English) [movie-rating].html new file mode 100644 index 00000000..e60b9b17 --- /dev/null +++ b/leetcode-cn/problem (English)/电影评分(English) [movie-rating].html @@ -0,0 +1,103 @@ +

Table: Movies

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| movie_id      | int     |
+| title         | varchar |
++---------------+---------+
+movie_id is the primary key (column with unique values) for this table.
+title is the name of the movie.
+
+ +

 

+ +

Table: Users

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| user_id       | int     |
+| name          | varchar |
++---------------+---------+
+user_id is the primary key (column with unique values) for this table.
+
+ +

 

+ +

Table: MovieRating

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| movie_id      | int     |
+| user_id       | int     |
+| rating        | int     |
+| created_at    | date    |
++---------------+---------+
+(movie_id, user_id) is the primary key (column with unique values) for this table.
+This table contains the rating of a movie by a user in their review.
+created_at is the user's review date. 
+
+ +

 

+ +

Write a solution to:

+ +
    +
  • Find the name of the user who has rated the greatest number of movies. In case of a tie, return the lexicographically smaller user name.
  • +
  • Find the movie name with the highest average rating in February 2020. In case of a tie, return the lexicographically smaller movie name.
  • +
+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Movies table:
++-------------+--------------+
+| movie_id    |  title       |
++-------------+--------------+
+| 1           | Avengers     |
+| 2           | Frozen 2     |
+| 3           | Joker        |
++-------------+--------------+
+Users table:
++-------------+--------------+
+| user_id     |  name        |
++-------------+--------------+
+| 1           | Daniel       |
+| 2           | Monica       |
+| 3           | Maria        |
+| 4           | James        |
++-------------+--------------+
+MovieRating table:
++-------------+--------------+--------------+-------------+
+| movie_id    | user_id      | rating       | created_at  |
++-------------+--------------+--------------+-------------+
+| 1           | 1            | 3            | 2020-01-12  |
+| 1           | 2            | 4            | 2020-02-11  |
+| 1           | 3            | 2            | 2020-02-12  |
+| 1           | 4            | 1            | 2020-01-01  |
+| 2           | 1            | 5            | 2020-02-17  | 
+| 2           | 2            | 2            | 2020-02-01  | 
+| 2           | 3            | 2            | 2020-03-01  |
+| 3           | 1            | 3            | 2020-02-22  | 
+| 3           | 2            | 4            | 2020-02-25  | 
++-------------+--------------+--------------+-------------+
+Output: 
++--------------+
+| results      |
++--------------+
+| Daniel       |
+| Frozen 2     |
++--------------+
+Explanation: 
+Daniel and Monica have rated 3 movies ("Avengers", "Frozen 2" and "Joker") but Daniel is smaller lexicographically.
+Frozen 2 and Joker have a rating average of 3.5 in February but Frozen 2 is smaller lexicographically.
+
diff --git a/leetcode-cn/problem (English)/砍竹子 I(English) [jian-sheng-zi-lcof].html b/leetcode-cn/problem (English)/砍竹子 I(English) [jian-sheng-zi-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/砍竹子 I(English) [jian-sheng-zi-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/砍竹子 II(English) [jian-sheng-zi-ii-lcof].html b/leetcode-cn/problem (English)/砍竹子 II(English) [jian-sheng-zi-ii-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/砍竹子 II(English) [jian-sheng-zi-ii-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/破解闯关密码(English) [ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof].html b/leetcode-cn/problem (English)/破解闯关密码(English) [ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/破解闯关密码(English) [ba-shu-zu-pai-cheng-zui-xiao-de-shu-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/确认率(English) [confirmation-rate].html b/leetcode-cn/problem (English)/确认率(English) [confirmation-rate].html new file mode 100644 index 00000000..d528355b --- /dev/null +++ b/leetcode-cn/problem (English)/确认率(English) [confirmation-rate].html @@ -0,0 +1,82 @@ +

Table: Signups

+ +
++----------------+----------+
+| Column Name    | Type     |
++----------------+----------+
+| user_id        | int      |
+| time_stamp     | datetime |
++----------------+----------+
+user_id is the column of unique values for this table.
+Each row contains information about the signup time for the user with ID user_id.
+
+ +

 

+ +

Table: Confirmations

+ +
++----------------+----------+
+| Column Name    | Type     |
++----------------+----------+
+| user_id        | int      |
+| time_stamp     | datetime |
+| action         | ENUM     |
++----------------+----------+
+(user_id, time_stamp) is the primary key (combination of columns with unique values) for this table.
+user_id is a foreign key (reference column) to the Signups table.
+action is an ENUM (category) of the type ('confirmed', 'timeout')
+Each row of this table indicates that the user with ID user_id requested a confirmation message at time_stamp and that confirmation message was either confirmed ('confirmed') or expired without confirming ('timeout').
+
+ +

 

+ +

The confirmation rate of a user is the number of 'confirmed' messages divided by the total number of requested confirmation messages. The confirmation rate of a user that did not request any confirmation messages is 0. Round the confirmation rate to two decimal places.

+ +

Write a solution to find the confirmation rate of each user.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Signups table:
++---------+---------------------+
+| user_id | time_stamp          |
++---------+---------------------+
+| 3       | 2020-03-21 10:16:13 |
+| 7       | 2020-01-04 13:57:59 |
+| 2       | 2020-07-29 23:09:44 |
+| 6       | 2020-12-09 10:39:37 |
++---------+---------------------+
+Confirmations table:
++---------+---------------------+-----------+
+| user_id | time_stamp          | action    |
++---------+---------------------+-----------+
+| 3       | 2021-01-06 03:30:46 | timeout   |
+| 3       | 2021-07-14 14:00:00 | timeout   |
+| 7       | 2021-06-12 11:57:29 | confirmed |
+| 7       | 2021-06-13 12:58:28 | confirmed |
+| 7       | 2021-06-14 13:59:27 | confirmed |
+| 2       | 2021-01-22 00:00:00 | confirmed |
+| 2       | 2021-02-28 23:59:59 | timeout   |
++---------+---------------------+-----------+
+Output: 
++---------+-------------------+
+| user_id | confirmation_rate |
++---------+-------------------+
+| 6       | 0.00              |
+| 3       | 0.00              |
+| 7       | 1.00              |
+| 2       | 0.50              |
++---------+-------------------+
+Explanation: 
+User 6 did not request any confirmation messages. The confirmation rate is 0.
+User 3 made 2 requests and both timed out. The confirmation rate is 0.
+User 7 made 3 requests and all were confirmed. The confirmation rate is 1.
+User 2 made 2 requests where one was confirmed and the other timed out. The confirmation rate is 1 / 2 = 0.5.
+
diff --git a/leetcode-cn/problem (English)/秋叶收藏集(English) [UlBDOe].html b/leetcode-cn/problem (English)/秋叶收藏集(English) [UlBDOe].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/秋叶收藏集(English) [UlBDOe].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/积木拼接(English) [De4qBB].html b/leetcode-cn/problem (English)/积木拼接(English) [De4qBB].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/积木拼接(English) [De4qBB].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/符文储备(English) [W2ZX4X].html b/leetcode-cn/problem (English)/符文储备(English) [W2ZX4X].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/符文储备(English) [W2ZX4X].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/统计同质子字符串的数目(English) [count-number-of-homogenous-substrings].html b/leetcode-cn/problem (English)/统计同质子字符串的数目(English) [count-number-of-homogenous-substrings].html new file mode 100644 index 00000000..0ade1829 --- /dev/null +++ b/leetcode-cn/problem (English)/统计同质子字符串的数目(English) [count-number-of-homogenous-substrings].html @@ -0,0 +1,43 @@ +

Given a string s, return the number of homogenous substrings of s. Since the answer may be too large, return it modulo 109 + 7.

+ +

A string is homogenous if all the characters of the string are the same.

+ +

A substring is a contiguous sequence of characters within a string.

+ +

 

+

Example 1:

+ +
+Input: s = "abbcccaa"
+Output: 13
+Explanation: The homogenous substrings are listed as below:
+"a"   appears 3 times.
+"aa"  appears 1 time.
+"b"   appears 2 times.
+"bb"  appears 1 time.
+"c"   appears 3 times.
+"cc"  appears 2 times.
+"ccc" appears 1 time.
+3 + 1 + 2 + 1 + 3 + 2 + 1 = 13.
+ +

Example 2:

+ +
+Input: s = "xy"
+Output: 2
+Explanation: The homogenous substrings are "x" and "y".
+ +

Example 3:

+ +
+Input: s = "zzzzz"
+Output: 15
+
+ +

 

+

Constraints:

+ +
    +
  • 1 <= s.length <= 105
  • +
  • s consists of lowercase letters.
  • +
diff --git a/leetcode-cn/problem (English)/统计目标成绩的出现次数(English) [zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof].html b/leetcode-cn/problem (English)/统计目标成绩的出现次数(English) [zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/统计目标成绩的出现次数(English) [zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/统计结果概率(English) [nge-tou-zi-de-dian-shu-lcof].html b/leetcode-cn/problem (English)/统计结果概率(English) [nge-tou-zi-de-dian-shu-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/统计结果概率(English) [nge-tou-zi-de-dian-shu-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/美观的花束(English) [1GxJYY].html b/leetcode-cn/problem (English)/美观的花束(English) [1GxJYY].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/美观的花束(English) [1GxJYY].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/翻转二叉树(English) [er-cha-shu-de-jing-xiang-lcof].html b/leetcode-cn/problem (English)/翻转二叉树(English) [er-cha-shu-de-jing-xiang-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/翻转二叉树(English) [er-cha-shu-de-jing-xiang-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/自行车炫技赛场(English) [kplEvH].html b/leetcode-cn/problem (English)/自行车炫技赛场(English) [kplEvH].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/自行车炫技赛场(English) [kplEvH].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/至少有5名直接下属的经理(English) [managers-with-at-least-5-direct-reports].html b/leetcode-cn/problem (English)/至少有5名直接下属的经理(English) [managers-with-at-least-5-direct-reports].html new file mode 100644 index 00000000..61b8b3b1 --- /dev/null +++ b/leetcode-cn/problem (English)/至少有5名直接下属的经理(English) [managers-with-at-least-5-direct-reports].html @@ -0,0 +1,48 @@ +

Table: Employee

+ +
++-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| id          | int     |
+| name        | varchar |
+| department  | varchar |
+| managerId   | int     |
++-------------+---------+
+id is the primary key (column with unique values) for this table.
+Each row of this table indicates the name of an employee, their department, and the id of their manager.
+If managerId is null, then the employee does not have a manager.
+No employee will be the manager of themself.
+
+ +

 

+ +

Write a solution to find managers with at least five direct reports.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Employee table:
++-----+-------+------------+-----------+
+| id  | name  | department | managerId |
++-----+-------+------------+-----------+
+| 101 | John  | A          | null      |
+| 102 | Dan   | A          | 101       |
+| 103 | James | A          | 101       |
+| 104 | Amy   | A          | 101       |
+| 105 | Anne  | A          | 101       |
+| 106 | Ron   | B          | 101       |
++-----+-------+------------+-----------+
+Output: 
++------+
+| name |
++------+
+| John |
++------+
+
diff --git a/leetcode-cn/problem (English)/舒适的湿度(English) [3aqs1c].html b/leetcode-cn/problem (English)/舒适的湿度(English) [3aqs1c].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/舒适的湿度(English) [3aqs1c].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/获取 DataFrame 的大小(English) [get-the-size-of-a-dataframe].html b/leetcode-cn/problem (English)/获取 DataFrame 的大小(English) [get-the-size-of-a-dataframe].html new file mode 100644 index 00000000..1c1cf8b7 --- /dev/null +++ b/leetcode-cn/problem (English)/获取 DataFrame 的大小(English) [get-the-size-of-a-dataframe].html @@ -0,0 +1,45 @@ +
+DataFrame players:
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| player_id   | int    |
+| name        | object |
+| age         | int    |
+| position    | object |
+| ...         | ...    |
++-------------+--------+
+
+ +

Write a solution to calculate and display the number of rows and columns of players.

+ +

Return the result as an array:

+ +

[number of rows, number of columns]

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input:
++-----------+----------+-----+-------------+--------------------+
+| player_id | name     | age | position    | team               |
++-----------+----------+-----+-------------+--------------------+
+| 846       | Mason    | 21  | Forward     | RealMadrid         |
+| 749       | Riley    | 30  | Winger      | Barcelona          |
+| 155       | Bob      | 28  | Striker     | ManchesterUnited   |
+| 583       | Isabella | 32  | Goalkeeper  | Liverpool          |
+| 388       | Zachary  | 24  | Midfielder  | BayernMunich       |
+| 883       | Ava      | 23  | Defender    | Chelsea            |
+| 355       | Violet   | 18  | Striker     | Juventus           |
+| 247       | Thomas   | 27  | Striker     | ParisSaint-Germain |
+| 761       | Jack     | 33  | Midfielder  | ManchesterCity     |
+| 642       | Charlie  | 36  | Center-back | Arsenal            |
++-----------+----------+-----+-------------+--------------------+
+Output:
+[10, 5]
+Explanation:
+This DataFrame contains 10 rows and 5 columns.
+
diff --git a/leetcode-cn/problem (English)/蓄水(English) [o8SXZn].html b/leetcode-cn/problem (English)/蓄水(English) [o8SXZn].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/蓄水(English) [o8SXZn].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/螺旋遍历二维数组(English) [shun-shi-zhen-da-yin-ju-zhen-lcof].html b/leetcode-cn/problem (English)/螺旋遍历二维数组(English) [shun-shi-zhen-da-yin-ju-zhen-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/螺旋遍历二维数组(English) [shun-shi-zhen-da-yin-ju-zhen-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/衣橱整理(English) [ji-qi-ren-de-yun-dong-fan-wei-lcof].html b/leetcode-cn/problem (English)/衣橱整理(English) [ji-qi-ren-de-yun-dong-fan-wei-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/衣橱整理(English) [ji-qi-ren-de-yun-dong-fan-wei-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/补给马车(English) [hqCnmP].html b/leetcode-cn/problem (English)/补给马车(English) [hqCnmP].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/补给马车(English) [hqCnmP].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/装饰树(English) [KnLfVT].html b/leetcode-cn/problem (English)/装饰树(English) [KnLfVT].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/装饰树(English) [KnLfVT].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/解密数字(English) [ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof].html b/leetcode-cn/problem (English)/解密数字(English) [ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/解密数字(English) [ba-shu-zi-fan-yi-cheng-zi-fu-chuan-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/训练计划 I(English) [diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof].html b/leetcode-cn/problem (English)/训练计划 I(English) [diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof].html new file mode 100644 index 00000000..5c5502aa --- /dev/null +++ b/leetcode-cn/problem (English)/训练计划 I(English) [diao-zheng-shu-zu-shun-xu-shi-qi-shu-wei-yu-ou-shu-qian-mian-lcof].html @@ -0,0 +1 @@ +

English description is not available for the problem. Please switch to Chinese.

diff --git a/leetcode-cn/problem (English)/训练计划 II(English) [lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof].html b/leetcode-cn/problem (English)/训练计划 II(English) [lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof].html new file mode 100644 index 00000000..5c5502aa --- /dev/null +++ b/leetcode-cn/problem (English)/训练计划 II(English) [lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof].html @@ -0,0 +1 @@ +

English description is not available for the problem. Please switch to Chinese.

diff --git a/leetcode-cn/problem (English)/训练计划 III(English) [fan-zhuan-lian-biao-lcof].html b/leetcode-cn/problem (English)/训练计划 III(English) [fan-zhuan-lian-biao-lcof].html new file mode 100644 index 00000000..5c5502aa --- /dev/null +++ b/leetcode-cn/problem (English)/训练计划 III(English) [fan-zhuan-lian-biao-lcof].html @@ -0,0 +1 @@ +

English description is not available for the problem. Please switch to Chinese.

diff --git a/leetcode-cn/problem (English)/训练计划 IV(English) [he-bing-liang-ge-pai-xu-de-lian-biao-lcof].html b/leetcode-cn/problem (English)/训练计划 IV(English) [he-bing-liang-ge-pai-xu-de-lian-biao-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/训练计划 IV(English) [he-bing-liang-ge-pai-xu-de-lian-biao-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/训练计划 V(English) [liang-ge-lian-biao-de-di-yi-ge-gong-gong-jie-dian-lcof].html b/leetcode-cn/problem (English)/训练计划 V(English) [liang-ge-lian-biao-de-di-yi-ge-gong-gong-jie-dian-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/训练计划 V(English) [liang-ge-lian-biao-de-di-yi-ge-gong-gong-jie-dian-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/训练计划 VI(English) [shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof].html b/leetcode-cn/problem (English)/训练计划 VI(English) [shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof].html new file mode 100644 index 00000000..5c5502aa --- /dev/null +++ b/leetcode-cn/problem (English)/训练计划 VI(English) [shu-zu-zhong-shu-zi-chu-xian-de-ci-shu-ii-lcof].html @@ -0,0 +1 @@ +

English description is not available for the problem. Please switch to Chinese.

diff --git a/leetcode-cn/problem (English)/设计机械累加器(English) [qiu-12n-lcof].html b/leetcode-cn/problem (English)/设计机械累加器(English) [qiu-12n-lcof].html new file mode 100644 index 00000000..5c5502aa --- /dev/null +++ b/leetcode-cn/problem (English)/设计机械累加器(English) [qiu-12n-lcof].html @@ -0,0 +1 @@ +

English description is not available for the problem. Please switch to Chinese.

diff --git a/leetcode-cn/problem (English)/设计自助结算系统(English) [dui-lie-de-zui-da-zhi-lcof].html b/leetcode-cn/problem (English)/设计自助结算系统(English) [dui-lie-de-zui-da-zhi-lcof].html new file mode 100644 index 00000000..5c5502aa --- /dev/null +++ b/leetcode-cn/problem (English)/设计自助结算系统(English) [dui-lie-de-zui-da-zhi-lcof].html @@ -0,0 +1 @@ +

English description is not available for the problem. Please switch to Chinese.

diff --git a/leetcode-cn/problem (English)/路径加密(English) [ti-huan-kong-ge-lcof].html b/leetcode-cn/problem (English)/路径加密(English) [ti-huan-kong-ge-lcof].html new file mode 100644 index 00000000..5c5502aa --- /dev/null +++ b/leetcode-cn/problem (English)/路径加密(English) [ti-huan-kong-ge-lcof].html @@ -0,0 +1 @@ +

English description is not available for the problem. Please switch to Chinese.

diff --git a/leetcode-cn/problem (English)/跳跃训练(English) [qing-wa-tiao-tai-jie-wen-ti-lcof].html b/leetcode-cn/problem (English)/跳跃训练(English) [qing-wa-tiao-tai-jie-wen-ti-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/跳跃训练(English) [qing-wa-tiao-tai-jie-wen-ti-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/连续天数的最高销售额(English) [lian-xu-zi-shu-zu-de-zui-da-he-lcof].html b/leetcode-cn/problem (English)/连续天数的最高销售额(English) [lian-xu-zi-shu-zu-de-zui-da-he-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/连续天数的最高销售额(English) [lian-xu-zi-shu-zu-de-zui-da-he-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/追逐游戏(English) [Za25hA].html b/leetcode-cn/problem (English)/追逐游戏(English) [Za25hA].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/追逐游戏(English) [Za25hA].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/速算机器人(English) [nGK0Fy].html b/leetcode-cn/problem (English)/速算机器人(English) [nGK0Fy].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/速算机器人(English) [nGK0Fy].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/采购方案(English) [4xy4Wx].html b/leetcode-cn/problem (English)/采购方案(English) [4xy4Wx].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/采购方案(English) [4xy4Wx].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/采集果实(English) [PTXy4P].html b/leetcode-cn/problem (English)/采集果实(English) [PTXy4P].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/采集果实(English) [PTXy4P].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/重命名列(English) [rename-columns].html b/leetcode-cn/problem (English)/重命名列(English) [rename-columns].html new file mode 100644 index 00000000..8ee3fe1f --- /dev/null +++ b/leetcode-cn/problem (English)/重命名列(English) [rename-columns].html @@ -0,0 +1,48 @@ +
+DataFrame students
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| id          | int    |
+| first       | object |
+| last        | object |
+| age         | int    |
++-------------+--------+
+
+ +

Write a solution to rename the columns as follows:

+ +
    +
  • id to student_id
  • +
  • first to first_name
  • +
  • last to last_name
  • +
  • age to age_in_years
  • +
+ +

The result format is in the following example.

+ +

 

+
+Example 1:
+Input:
++----+---------+----------+-----+
+| id | first   | last     | age |
++----+---------+----------+-----+
+| 1  | Mason   | King     | 6   |
+| 2  | Ava     | Wright   | 7   |
+| 3  | Taylor  | Hall     | 16  |
+| 4  | Georgia | Thompson | 18  |
+| 5  | Thomas  | Moore    | 10  |
++----+---------+----------+-----+
+Output:
++------------+------------+-----------+--------------+
+| student_id | first_name | last_name | age_in_years |
++------------+------------+-----------+--------------+
+| 1          | Mason      | King      | 6            |
+| 2          | Ava        | Wright    | 7            |
+| 3          | Taylor     | Hall      | 16           |
+| 4          | Georgia    | Thompson  | 18           |
+| 5          | Thomas     | Moore     | 10           |
++------------+------------+-----------+--------------+
+Explanation: 
+The column names are changed accordingly.
diff --git a/leetcode-cn/problem (English)/重塑数据:融合(English) [reshape-data-melt].html b/leetcode-cn/problem (English)/重塑数据:融合(English) [reshape-data-melt].html new file mode 100644 index 00000000..2eb7ad90 --- /dev/null +++ b/leetcode-cn/problem (English)/重塑数据:融合(English) [reshape-data-melt].html @@ -0,0 +1,44 @@ +
+DataFrame report
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| product     | object |
+| quarter_1   | int    |
+| quarter_2   | int    |
+| quarter_3   | int    |
+| quarter_4   | int    |
++-------------+--------+
+
+ +

Write a solution to reshape the data so that each row represents sales data for a product in a specific quarter.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input:
++-------------+-----------+-----------+-----------+-----------+
+| product     | quarter_1 | quarter_2 | quarter_3 | quarter_4 |
++-------------+-----------+-----------+-----------+-----------+
+| Umbrella    | 417       | 224       | 379       | 611       |
+| SleepingBag | 800       | 936       | 93        | 875       |
++-------------+-----------+-----------+-----------+-----------+
+Output:
++-------------+-----------+-------+
+| product     | quarter   | sales |
++-------------+-----------+-------+
+| Umbrella    | quarter_1 | 417   |
+| SleepingBag | quarter_1 | 800   |
+| Umbrella    | quarter_2 | 224   |
+| SleepingBag | quarter_2 | 936   |
+| Umbrella    | quarter_3 | 379   |
+| SleepingBag | quarter_3 | 93    |
+| Umbrella    | quarter_4 | 611   |
+| SleepingBag | quarter_4 | 875   |
++-------------+-----------+-------+
+Explanation:
+The DataFrame is reshaped from wide to long format. Each row represents the sales of a product in a quarter.
+
diff --git a/leetcode-cn/problem (English)/重塑数据:连结(English) [reshape-data-concatenate].html b/leetcode-cn/problem (English)/重塑数据:连结(English) [reshape-data-concatenate].html new file mode 100644 index 00000000..72f2e797 --- /dev/null +++ b/leetcode-cn/problem (English)/重塑数据:连结(English) [reshape-data-concatenate].html @@ -0,0 +1,59 @@ +
+DataFrame df1
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| student_id  | int    |
+| name        | object |
+| age         | int    |
++-------------+--------+
+
+DataFrame df2
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| student_id  | int    |
+| name        | object |
+| age         | int    |
++-------------+--------+
+
+
+ +

Write a solution to concatenate these two DataFrames vertically into one DataFrame.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input:
+df1
++------------+---------+-----+
+| student_id | name    | age |
++------------+---------+-----+
+| 1          | Mason   | 8   |
+| 2          | Ava     | 6   |
+| 3          | Taylor  | 15  |
+| 4          | Georgia | 17  |
++------------+---------+-----+
+df2
++------------+------+-----+
+| student_id | name | age |
++------------+------+-----+
+| 5          | Leo  | 7   |
+| 6          | Alex | 7   |
++------------+------+-----+
+Output:
++------------+---------+-----+
+| student_id | name    | age |
++------------+---------+-----+
+| 1          | Mason   | 8   |
+| 2          | Ava     | 6   |
+| 3          | Taylor  | 15  |
+| 4          | Georgia | 17  |
+| 5          | Leo     | 7   |
+| 6          | Alex    | 7   |
++------------+---------+-----+
+Explanation:
+The two DataFramess are stacked vertically, and their rows are combined.
diff --git a/leetcode-cn/problem (English)/集水器(English) [kskhHQ].html b/leetcode-cn/problem (English)/集水器(English) [kskhHQ].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/集水器(English) [kskhHQ].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/项目员工 I(English) [project-employees-i].html b/leetcode-cn/problem (English)/项目员工 I(English) [project-employees-i].html new file mode 100644 index 00000000..4b349af9 --- /dev/null +++ b/leetcode-cn/problem (English)/项目员工 I(English) [project-employees-i].html @@ -0,0 +1,71 @@ +

Table: Project

+ +
++-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| project_id  | int     |
+| employee_id | int     |
++-------------+---------+
+(project_id, employee_id) is the primary key of this table.
+employee_id is a foreign key to Employee table.
+Each row of this table indicates that the employee with employee_id is working on the project with project_id.
+
+ +

 

+ +

Table: Employee

+ +
++------------------+---------+
+| Column Name      | Type    |
++------------------+---------+
+| employee_id      | int     |
+| name             | varchar |
+| experience_years | int     |
++------------------+---------+
+employee_id is the primary key of this table. It's guaranteed that experience_years is not NULL.
+Each row of this table contains information about one employee.
+
+ +

 

+ +

Write an SQL query that reports the average experience years of all the employees for each project, rounded to 2 digits.

+ +

Return the result table in any order.

+ +

The query result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Project table:
++-------------+-------------+
+| project_id  | employee_id |
++-------------+-------------+
+| 1           | 1           |
+| 1           | 2           |
+| 1           | 3           |
+| 2           | 1           |
+| 2           | 4           |
++-------------+-------------+
+Employee table:
++-------------+--------+------------------+
+| employee_id | name   | experience_years |
++-------------+--------+------------------+
+| 1           | Khaled | 3                |
+| 2           | Ali    | 2                |
+| 3           | John   | 1                |
+| 4           | Doe    | 2                |
++-------------+--------+------------------+
+Output: 
++-------------+---------------+
+| project_id  | average_years |
++-------------+---------------+
+| 1           | 2.00          |
+| 2           | 2.50          |
++-------------+---------------+
+Explanation: The average experience years for the first project is (3 + 2 + 1) / 3 = 2.00 and for the second project is (3 + 2) / 2 = 2.50
+
diff --git a/leetcode-cn/problem (English)/餐馆营业额变化增长(English) [restaurant-growth].html b/leetcode-cn/problem (English)/餐馆营业额变化增长(English) [restaurant-growth].html new file mode 100644 index 00000000..d995bc1e --- /dev/null +++ b/leetcode-cn/problem (English)/餐馆营业额变化增长(English) [restaurant-growth].html @@ -0,0 +1,63 @@ +

Table: Customer

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| customer_id   | int     |
+| name          | varchar |
+| visited_on    | date    |
+| amount        | int     |
++---------------+---------+
+In SQL,(customer_id, visited_on) is the primary key for this table.
+This table contains data about customer transactions in a restaurant.
+visited_on is the date on which the customer with ID (customer_id) has visited the restaurant.
+amount is the total paid by a customer.
+
+ +

 

+ +

You are the restaurant owner and you want to analyze a possible expansion (there will be at least one customer every day).

+ +

Compute the moving average of how much the customer paid in a seven days window (i.e., current day + 6 days before). average_amount should be rounded to two decimal places.

+ +

Return the result table ordered by visited_on in ascending order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Customer table:
++-------------+--------------+--------------+-------------+
+| customer_id | name         | visited_on   | amount      |
++-------------+--------------+--------------+-------------+
+| 1           | Jhon         | 2019-01-01   | 100         |
+| 2           | Daniel       | 2019-01-02   | 110         |
+| 3           | Jade         | 2019-01-03   | 120         |
+| 4           | Khaled       | 2019-01-04   | 130         |
+| 5           | Winston      | 2019-01-05   | 110         | 
+| 6           | Elvis        | 2019-01-06   | 140         | 
+| 7           | Anna         | 2019-01-07   | 150         |
+| 8           | Maria        | 2019-01-08   | 80          |
+| 9           | Jaze         | 2019-01-09   | 110         | 
+| 1           | Jhon         | 2019-01-10   | 130         | 
+| 3           | Jade         | 2019-01-10   | 150         | 
++-------------+--------------+--------------+-------------+
+Output: 
++--------------+--------------+----------------+
+| visited_on   | amount       | average_amount |
++--------------+--------------+----------------+
+| 2019-01-07   | 860          | 122.86         |
+| 2019-01-08   | 840          | 120            |
+| 2019-01-09   | 840          | 120            |
+| 2019-01-10   | 1000         | 142.86         |
++--------------+--------------+----------------+
+Explanation: 
+1st moving average from 2019-01-01 to 2019-01-07 has an average_amount of (100 + 110 + 120 + 130 + 110 + 140 + 150)/7 = 122.86
+2nd moving average from 2019-01-02 to 2019-01-08 has an average_amount of (110 + 120 + 130 + 110 + 140 + 150 + 80)/7 = 120
+3rd moving average from 2019-01-03 to 2019-01-09 has an average_amount of (120 + 130 + 110 + 140 + 150 + 80 + 110)/7 = 120
+4th moving average from 2019-01-04 to 2019-01-10 has an average_amount of (130 + 110 + 140 + 150 + 80 + 110 + 130 + 150)/7 = 142.86
+
diff --git a/leetcode-cn/problem (English)/验证二叉搜索树的后序遍历序列(English) [er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof].html b/leetcode-cn/problem (English)/验证二叉搜索树的后序遍历序列(English) [er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/验证二叉搜索树的后序遍历序列(English) [er-cha-sou-suo-shu-de-hou-xu-bian-li-xu-lie-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/验证回文串(English) [XltzEq].html b/leetcode-cn/problem (English)/验证回文串(English) [XltzEq].html new file mode 100644 index 00000000..579f7fd7 --- /dev/null +++ b/leetcode-cn/problem (English)/验证回文串(English) [XltzEq].html @@ -0,0 +1 @@ +

English description is not available for the problem. Please switch to Chinese.

diff --git a/leetcode-cn/problem (English)/验证图书取出顺序(English) [zhan-de-ya-ru-dan-chu-xu-lie-lcof].html b/leetcode-cn/problem (English)/验证图书取出顺序(English) [zhan-de-ya-ru-dan-chu-xu-lie-lcof].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/验证图书取出顺序(English) [zhan-de-ya-ru-dan-chu-xu-lie-lcof].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/验证外星语词典(English) [lwyVBB].html b/leetcode-cn/problem (English)/验证外星语词典(English) [lwyVBB].html new file mode 100644 index 00000000..579f7fd7 --- /dev/null +++ b/leetcode-cn/problem (English)/验证外星语词典(English) [lwyVBB].html @@ -0,0 +1 @@ +

English description is not available for the problem. Please switch to Chinese.

diff --git a/leetcode-cn/problem (English)/魔塔游戏(English) [p0NxJO].html b/leetcode-cn/problem (English)/魔塔游戏(English) [p0NxJO].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/魔塔游戏(English) [p0NxJO].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/魔术排列(English) [er94lq].html b/leetcode-cn/problem (English)/魔术排列(English) [er94lq].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/魔术排列(English) [er94lq].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/魔法棋盘(English) [1ybDKD].html b/leetcode-cn/problem (English)/魔法棋盘(English) [1ybDKD].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/魔法棋盘(English) [1ybDKD].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/黑白方格画(English) [ccw6C7].html b/leetcode-cn/problem (English)/黑白方格画(English) [ccw6C7].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/黑白方格画(English) [ccw6C7].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/黑白翻转棋(English) [fHi6rV].html b/leetcode-cn/problem (English)/黑白翻转棋(English) [fHi6rV].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/黑白翻转棋(English) [fHi6rV].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode-cn/problem (English)/黑盒光线反射(English) [IQvJ9i].html b/leetcode-cn/problem (English)/黑盒光线反射(English) [IQvJ9i].html new file mode 100644 index 00000000..49f88ad1 --- /dev/null +++ b/leetcode-cn/problem (English)/黑盒光线反射(English) [IQvJ9i].html @@ -0,0 +1 @@ +English description is not available for the problem. Please switch to Chinese. \ No newline at end of file diff --git a/leetcode/originData/[no content]array-of-objects-to-matrix.json b/leetcode/originData/[no content]array-of-objects-to-matrix.json new file mode 100644 index 00000000..e92cc26e --- /dev/null +++ b/leetcode/originData/[no content]array-of-objects-to-matrix.json @@ -0,0 +1,54 @@ +{ + "data": { + "question": { + "questionId": "2769", + "questionFrontendId": "2675", + "boundTopicId": null, + "title": "Array of Objects to Matrix", + "titleSlug": "array-of-objects-to-matrix", + "content": null, + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": true, + "difficulty": "Hard", + "likes": 130, + "dislikes": 72, + "isLiked": null, + "similarQuestions": "[{\"title\": \"JSON Deep Equal\", \"titleSlug\": \"json-deep-equal\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Convert Object to JSON String\", \"titleSlug\": \"convert-object-to-json-string\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]", + "exampleTestcases": "[{\"b\":1,\"a\":2},{\"b\":3,\"a\":4}]\n[{\"a\":1,\"b\":2},{\"c\":3,\"d\":4},{}]\n[{\"a\":{\"b\":1,\"c\":2}},{\"a\":{\"b\":3,\"d\":4}}]\n[[{\"a\":null}],[{\"b\":true}],[{\"c\":\"x\"}]]\n[{},{},{}]", + "categoryTitle": "JavaScript", + "contributors": [], + "topicTags": [], + "companyTagStats": null, + "codeSnippets": null, + "stats": "{\"totalAccepted\": \"5.8K\", \"totalSubmission\": \"8.3K\", \"totalAcceptedRaw\": 5761, \"totalSubmissionRaw\": 8290, \"acRate\": \"69.5%\"}", + "hints": [ + "How could you split the problem up into sub-problems?", + "1.) Write a function that converts a single object into a dictionary that maps the path name to values. You can solve this recursively by keeping track of current path list.", + "2.) Write a function that converts a list of dictionaries into a matrix. Start by creating a list of all possible paths in any of the dictionaries. This will represent the columns." + ], + "solution": { + "id": "1912", + "canSeeDetail": false, + "paidOnly": true, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "[{\"b\":1,\"a\":2},{\"b\":3,\"a\":4}]", + "metaData": "{\n \"name\": \"jsonToMatrix\",\n \"params\": [\n {\n \"name\": \"arr\",\n \"type\": \"string\"\n }\n ],\n \"return\": {\n \"type\": \"string\"\n },\n \"languages\": [\n \"typescript\",\n \"javascript\"\n ],\n \"manual\": true\n}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"javascript\": [\"JavaScript\", \"

Node.js 16.13.2.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES6 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\\r\\n\\r\\n

For Priority Queue / Queue data structures, you may use 5.3.0 version of datastructures-js/priority-queue and 4.2.1 version of datastructures-js/queue.

\"], \"typescript\": [\"Typescript\", \"

TypeScript 5.1.6, Node.js 16.13.2.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES2022 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/[no content]curry.json b/leetcode/originData/[no content]curry.json new file mode 100644 index 00000000..cdd7fc48 --- /dev/null +++ b/leetcode/originData/[no content]curry.json @@ -0,0 +1,53 @@ +{ + "data": { + "question": { + "questionId": "2740", + "questionFrontendId": "2632", + "boundTopicId": null, + "title": "Curry", + "titleSlug": "curry", + "content": null, + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": true, + "difficulty": "Medium", + "likes": 332, + "dislikes": 34, + "isLiked": null, + "similarQuestions": "[{\"title\": \"Memoize\", \"titleSlug\": \"memoize\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Memoize II\", \"titleSlug\": \"memoize-ii\", \"difficulty\": \"Hard\", \"translatedTitle\": null}]", + "exampleTestcases": "function sum(a, b, c) { return a + b + c; }\n[[1],[2],[3]]\nfunction sum(a, b, c) { return a + b + c; }\n[[1,2],[3]]\nfunction sum(a, b, c) { return a + b + c; }\n[[],[],[1,2,3]]\nfunction life() { return 42; }\n[[]]", + "categoryTitle": "JavaScript", + "contributors": [], + "topicTags": [], + "companyTagStats": null, + "codeSnippets": null, + "stats": "{\"totalAccepted\": \"15.1K\", \"totalSubmission\": \"16.9K\", \"totalAcceptedRaw\": 15129, \"totalSubmissionRaw\": 16937, \"acRate\": \"89.3%\"}", + "hints": [ + "You can access the count of parameters expected to passed into a function with \"fn.length\".", + "You can use recursion. If the length of params passed is equal to fn.length, you are done. Just pass those params to fn. Otherwise return a function that is includes the previous passed params plus the new params. The new function should contain a recursive call to curry()." + ], + "solution": { + "id": "1897", + "canSeeDetail": false, + "paidOnly": true, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "function sum(a, b, c) { return a + b + c; }\n[[1],[2],[3]]", + "metaData": "{\n \"name\": \"curry\",\n \"params\": [\n {\n \"name\": \"fn\",\n \"type\": \"string\"\n },\n {\n \"type\": \"integer[][]\",\n \"name\": \"inputs\"\n }\n ],\n \"return\": {\n \"type\": \"string\"\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\", \"

Node.js 16.13.2.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES6 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\\r\\n\\r\\n

For Priority Queue / Queue data structures, you may use 5.3.0 version of datastructures-js/priority-queue and 4.2.1 version of datastructures-js/queue.

\"], \"typescript\": [\"Typescript\", \"

TypeScript 5.1.6, Node.js 16.13.2.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES2022 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/[no content]differences-between-two-objects.json b/leetcode/originData/[no content]differences-between-two-objects.json new file mode 100644 index 00000000..5762c95d --- /dev/null +++ b/leetcode/originData/[no content]differences-between-two-objects.json @@ -0,0 +1,54 @@ +{ + "data": { + "question": { + "questionId": "2774", + "questionFrontendId": "2700", + "boundTopicId": null, + "title": "Differences Between Two Objects", + "titleSlug": "differences-between-two-objects", + "content": null, + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": true, + "difficulty": "Medium", + "likes": 132, + "dislikes": 19, + "isLiked": null, + "similarQuestions": "[{\"title\": \"JSON Deep Equal\", \"titleSlug\": \"json-deep-equal\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Convert Object to JSON String\", \"titleSlug\": \"convert-object-to-json-string\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]", + "exampleTestcases": "{}\n{\"a\": 1, \"b\": 2}\n{\"a\": 1, \"v\": 3, \"x\": [], \"z\": {\"a\": null}}\n{\"a\": 2, \"v\": 4, \"x\": [], \"z\": {\"a\": 2}}\n{\"a\": 5, \"v\": 6, \"z\": [1,2,4, [2,5,7]]}\n{\"a\": 5, \"v\": 7, \"z\": [1,2,3, [1]]}\n{\"a\":{\"b\":1}}\n{\"a\":[5]}\n{\"a\": [1, 2, {}],\"b\": false}\n{\"b\": false, \"a\": [1, 2, {}]}", + "categoryTitle": "JavaScript", + "contributors": [], + "topicTags": [], + "companyTagStats": null, + "codeSnippets": null, + "stats": "{\"totalAccepted\": \"5.7K\", \"totalSubmission\": \"7K\", \"totalAcceptedRaw\": 5737, \"totalSubmissionRaw\": 7038, \"acRate\": \"81.5%\"}", + "hints": [ + "Find the intersection of the keys/indices on the two arrays/objects.", + "Analyze the data structure recursively.", + "For each key in the intersection, omit if there are no differences in the leaves. Otherwise return the difference." + ], + "solution": { + "id": "1914", + "canSeeDetail": false, + "paidOnly": true, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "{}\n{\"a\": 1, \"b\": 2}", + "metaData": "{\n \"name\": \"objDiff\",\n \"params\": [\n {\n \"name\": \"obj1\",\n \"type\": \"string\"\n },\n {\n \"type\": \"string\",\n \"name\": \"obj2\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\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\", \"

Node.js 16.13.2.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES6 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\\r\\n\\r\\n

For Priority Queue / Queue data structures, you may use 5.3.0 version of datastructures-js/priority-queue and 4.2.1 version of datastructures-js/queue.

\"], \"typescript\": [\"Typescript\", \"

TypeScript 5.1.6, Node.js 16.13.2.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES2022 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/[no content]promise-pool.json b/leetcode/originData/[no content]promise-pool.json new file mode 100644 index 00000000..400b8419 --- /dev/null +++ b/leetcode/originData/[no content]promise-pool.json @@ -0,0 +1,53 @@ +{ + "data": { + "question": { + "questionId": "2750", + "questionFrontendId": "2636", + "boundTopicId": null, + "title": "Promise Pool", + "titleSlug": "promise-pool", + "content": null, + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": true, + "difficulty": "Medium", + "likes": 273, + "dislikes": 25, + "isLiked": null, + "similarQuestions": "[{\"title\": \"Sleep\", \"titleSlug\": \"sleep\", \"difficulty\": \"Easy\", \"translatedTitle\": null}, {\"title\": \"Promise Time Limit\", \"titleSlug\": \"promise-time-limit\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Cache With Time Limit\", \"titleSlug\": \"cache-with-time-limit\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Throttle\", \"titleSlug\": \"throttle\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]", + "exampleTestcases": "[() => new Promise(res => setTimeout(res, 300)), () => new Promise(res => setTimeout(res, 400)), () => new Promise(res => setTimeout(res, 200))]\n2\n[() => new Promise(res => setTimeout(res, 300)), () => new Promise(res => setTimeout(res, 400)), () => new Promise(res => setTimeout(res, 200))]\n5\n[() => new Promise(res => setTimeout(res, 300)), () => new Promise(res => setTimeout(res, 400)), () => new Promise(res => setTimeout(res, 200))]\n1", + "categoryTitle": "JavaScript", + "contributors": [], + "topicTags": [], + "companyTagStats": null, + "codeSnippets": null, + "stats": "{\"totalAccepted\": \"10.9K\", \"totalSubmission\": \"13.5K\", \"totalAcceptedRaw\": 10934, \"totalSubmissionRaw\": 13536, \"acRate\": \"80.8%\"}", + "hints": [ + "Initially execute all the functions until the queue fills up.", + "Every time a function resolves, add a new promise to the queue if possible." + ], + "solution": { + "id": "1901", + "canSeeDetail": false, + "paidOnly": true, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "[() => new Promise(res => setTimeout(res, 300)), () => new Promise(res => setTimeout(res, 400)), () => new Promise(res => setTimeout(res, 200))]\n2", + "metaData": "{\n \"name\": \"promisePool\",\n \"params\": [\n {\n \"name\": \"getFunctions\",\n \"type\": \"string\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"n\"\n }\n ],\n \"return\": {\n \"type\": \"string\"\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\", \"

Node.js 16.13.2.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES6 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\\r\\n\\r\\n

For Priority Queue / Queue data structures, you may use 5.3.0 version of datastructures-js/priority-queue and 4.2.1 version of datastructures-js/queue.

\"], \"typescript\": [\"Typescript\", \"

TypeScript 5.1.6, Node.js 16.13.2.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES2022 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/[no content]throttle.json b/leetcode/originData/[no content]throttle.json new file mode 100644 index 00000000..a1f3e4a7 --- /dev/null +++ b/leetcode/originData/[no content]throttle.json @@ -0,0 +1,54 @@ +{ + "data": { + "question": { + "questionId": "2771", + "questionFrontendId": "2676", + "boundTopicId": null, + "title": "Throttle", + "titleSlug": "throttle", + "content": null, + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": true, + "difficulty": "Medium", + "likes": 156, + "dislikes": 27, + "isLiked": null, + "similarQuestions": "[{\"title\": \"Debounce\", \"titleSlug\": \"debounce\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Promise Time Limit\", \"titleSlug\": \"promise-time-limit\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Promise Pool\", \"titleSlug\": \"promise-pool\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]", + "exampleTestcases": "100\n[{\"t\":20,\"inputs\":[1]}]\n50\n[{\"t\":50,\"inputs\":[1]},{\"t\":75,\"inputs\":[2]}]\n70\n[{\"t\":50,\"inputs\":[1]},{\"t\":75,\"inputs\":[2]},{\"t\":90,\"inputs\":[8]},{\"t\": 140, \"inputs\":[5,7]},{\"t\": 300, \"inputs\": [9,4]}]", + "categoryTitle": "JavaScript", + "contributors": [], + "topicTags": [], + "companyTagStats": null, + "codeSnippets": null, + "stats": "{\"totalAccepted\": \"7.9K\", \"totalSubmission\": \"9.5K\", \"totalAcceptedRaw\": 7916, \"totalSubmissionRaw\": 9511, \"acRate\": \"83.2%\"}", + "hints": [ + "Store a variable for currArguments.", + "If no timeout is in progress, immediately execute the function and create a timeout. If a timeout is in progress, set the currArguments to the new arguments.", + "When the timeout is done: if currArguments is null, do nothing. Otherwise, execute the function with currArguments and create another timeout." + ], + "solution": { + "id": "1908", + "canSeeDetail": false, + "paidOnly": true, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "100\n[{\"t\":20,\"inputs\":[1]}]", + "metaData": "{\n \"name\": \"throttle\",\n \"params\": [\n {\n \"name\": \"fn\",\n \"type\": \"string\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"t\"\n }\n ],\n \"return\": {\n \"type\": \"integer\"\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\", \"

Node.js 16.13.2.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES6 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\\r\\n\\r\\n

For Priority Queue / Queue data structures, you may use 5.3.0 version of datastructures-js/priority-queue and 4.2.1 version of datastructures-js/queue.

\"], \"typescript\": [\"Typescript\", \"

TypeScript 5.1.6, Node.js 16.13.2.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES2022 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/average-selling-price.json b/leetcode/originData/average-selling-price.json new file mode 100644 index 00000000..9030e3ee --- /dev/null +++ b/leetcode/originData/average-selling-price.json @@ -0,0 +1,101 @@ +{ + "data": { + "question": { + "questionId": "1390", + "questionFrontendId": "1251", + "boundTopicId": null, + "title": "Average Selling Price", + "titleSlug": "average-selling-price", + "content": "

Table: Prices

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| start_date    | date    |\n| end_date      | date    |\n| price         | int     |\n+---------------+---------+\n(product_id, start_date, end_date) is the primary key (combination of columns with unique values) for this table.\nEach row of this table indicates the price of the product_id in the period from start_date to end_date.\nFor each product_id there will be no two overlapping periods. That means there will be no two intersecting periods for the same product_id.\n
\n\n

 

\n\n

Table: UnitsSold

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| purchase_date | date    |\n| units         | int     |\n+---------------+---------+\nThis table may contain duplicate rows.\nEach row of this table indicates the date, units, and product_id of each product sold. \n
\n\n

 

\n\n

Write a solution to find the average selling price for each product. average_price should be rounded to 2 decimal places.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nPrices table:\n+------------+------------+------------+--------+\n| product_id | start_date | end_date   | price  |\n+------------+------------+------------+--------+\n| 1          | 2019-02-17 | 2019-02-28 | 5      |\n| 1          | 2019-03-01 | 2019-03-22 | 20     |\n| 2          | 2019-02-01 | 2019-02-20 | 15     |\n| 2          | 2019-02-21 | 2019-03-31 | 30     |\n+------------+------------+------------+--------+\nUnitsSold table:\n+------------+---------------+-------+\n| product_id | purchase_date | units |\n+------------+---------------+-------+\n| 1          | 2019-02-25    | 100   |\n| 1          | 2019-03-01    | 15    |\n| 2          | 2019-02-10    | 200   |\n| 2          | 2019-03-22    | 30    |\n+------------+---------------+-------+\nOutput: \n+------------+---------------+\n| product_id | average_price |\n+------------+---------------+\n| 1          | 6.96          |\n| 2          | 16.96         |\n+------------+---------------+\nExplanation: \nAverage selling price = Total Price of Product / Number of products sold.\nAverage selling price for product 1 = ((100 * 5) + (15 * 20)) / 115 = 6.96\nAverage selling price for product 2 = ((200 * 15) + (30 * 30)) / 230 = 16.96\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 860, + "dislikes": 89, + "isLiked": null, + "similarQuestions": "[]", + "exampleTestcases": "{\"headers\":{\"Prices\":[\"product_id\",\"start_date\",\"end_date\",\"price\"],\"UnitsSold\":[\"product_id\",\"purchase_date\",\"units\"]},\"rows\":{\"Prices\":[[1,\"2019-02-17\",\"2019-02-28\",5],[1,\"2019-03-01\",\"2019-03-22\",20],[2,\"2019-02-01\",\"2019-02-20\",15],[2,\"2019-02-21\",\"2019-03-31\",30]],\"UnitsSold\":[[1,\"2019-02-25\",100],[1,\"2019-03-01\",15],[2,\"2019-02-10\",200],[2,\"2019-03-22\",30]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef average_selling_price(prices: pd.DataFrame, units_sold: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"133.2K\", \"totalSubmission\": \"261.7K\", \"totalAcceptedRaw\": 133231, \"totalSubmissionRaw\": 261739, \"acRate\": \"50.9%\"}", + "hints": [], + "solution": { + "id": "2138", + "canSeeDetail": true, + "paidOnly": false, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "{\"headers\":{\"Prices\":[\"product_id\",\"start_date\",\"end_date\",\"price\"],\"UnitsSold\":[\"product_id\",\"purchase_date\",\"units\"]},\"rows\":{\"Prices\":[[1,\"2019-02-17\",\"2019-02-28\",5],[1,\"2019-03-01\",\"2019-03-22\",20],[2,\"2019-02-01\",\"2019-02-20\",15],[2,\"2019-02-21\",\"2019-03-31\",30]],\"UnitsSold\":[[1,\"2019-02-25\",100],[1,\"2019-03-01\",15],[2,\"2019-02-10\",200],[2,\"2019-03-22\",30]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Prices (product_id int, start_date date, end_date date, price int)\", \"Create table If Not Exists UnitsSold (product_id int, purchase_date date, units int)\"], \"mssql\": [\"Create table Prices (product_id int, start_date date, end_date date, price int)\", \"Create table UnitsSold (product_id int, purchase_date date, units int)\"], \"oraclesql\": [\"Create table Prices (product_id int, start_date date, end_date date, price int)\", \"Create table UnitsSold (product_id int, purchase_date date, units int)\", \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"], \"database\": true, \"name\": \"average_selling_price\", \"pythondata\": [\"Prices = pd.DataFrame([], columns=['product_id', 'start_date', 'end_date', 'price']).astype({'product_id':'Int64', 'start_date':'datetime64[ns]', 'end_date':'datetime64[ns]', 'price':'Int64'})\", \"UnitsSold = pd.DataFrame([], columns=['product_id', 'purchase_date', 'units']).astype({'product_id':'Int64', 'purchase_date':'datetime64[ns]', 'units':'Int64'})\"], \"postgresql\": [\"\\nCreate table If Not Exists Prices (product_id int, start_date date, end_date date, price int)\\n\", \"Create table If Not Exists UnitsSold (product_id int, purchase_date date, units int)\"], \"database_schema\": {\"Prices\": {\"product_id\": \"INT\", \"start_date\": \"DATE\", \"end_date\": \"DATE\", \"price\": \"INT\"}, \"UnitsSold\": {\"product_id\": \"INT\", \"purchase_date\": \"DATE\", \"units\": \"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Prices (product_id int, start_date date, end_date date, price int)", + "Create table If Not Exists UnitsSold (product_id int, purchase_date date, units int)", + "Truncate table Prices", + "insert into Prices (product_id, start_date, end_date, price) values ('1', '2019-02-17', '2019-02-28', '5')", + "insert into Prices (product_id, start_date, end_date, price) values ('1', '2019-03-01', '2019-03-22', '20')", + "insert into Prices (product_id, start_date, end_date, price) values ('2', '2019-02-01', '2019-02-20', '15')", + "insert into Prices (product_id, start_date, end_date, price) values ('2', '2019-02-21', '2019-03-31', '30')", + "Truncate table UnitsSold", + "insert into UnitsSold (product_id, purchase_date, units) values ('1', '2019-02-25', '100')", + "insert into UnitsSold (product_id, purchase_date, units) values ('1', '2019-03-01', '15')", + "insert into UnitsSold (product_id, purchase_date, units) values ('2', '2019-02-10', '200')", + "insert into UnitsSold (product_id, purchase_date, units) values ('2', '2019-03-22', '30')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/average-time-of-process-per-machine.json b/leetcode/originData/average-time-of-process-per-machine.json new file mode 100644 index 00000000..ea3b86e2 --- /dev/null +++ b/leetcode/originData/average-time-of-process-per-machine.json @@ -0,0 +1,103 @@ +{ + "data": { + "question": { + "questionId": "1801", + "questionFrontendId": "1661", + "boundTopicId": null, + "title": "Average Time of Process per Machine", + "titleSlug": "average-time-of-process-per-machine", + "content": "

Table: Activity

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| machine_id     | int     |\n| process_id     | int     |\n| activity_type  | enum    |\n| timestamp      | float   |\n+----------------+---------+\nThe table shows the user activities for a factory website.\n(machine_id, process_id, activity_type) is the primary key (combination of columns with unique values) of this table.\nmachine_id is the ID of a machine.\nprocess_id is the ID of a process running on the machine with ID machine_id.\nactivity_type is an ENUM (category) of type ('start', 'end').\ntimestamp is a float representing the current time in seconds.\n'start' means the machine starts the process at the given timestamp and 'end' means the machine ends the process at the given timestamp.\nThe 'start' timestamp will always be before the 'end' timestamp for every (machine_id, process_id) pair.
\n\n

 

\n\n

There is a factory website that has several machines each running the same number of processes. Write a solution to find the average time each machine takes to complete a process.

\n\n

The time to complete a process is the 'end' timestamp minus the 'start' timestamp. The average time is calculated by the total time to complete every process on the machine divided by the number of processes that were run.

\n\n

The resulting table should have the machine_id along with the average time as processing_time, which should be rounded to 3 decimal places.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nActivity table:\n+------------+------------+---------------+-----------+\n| machine_id | process_id | activity_type | timestamp |\n+------------+------------+---------------+-----------+\n| 0          | 0          | start         | 0.712     |\n| 0          | 0          | end           | 1.520     |\n| 0          | 1          | start         | 3.140     |\n| 0          | 1          | end           | 4.120     |\n| 1          | 0          | start         | 0.550     |\n| 1          | 0          | end           | 1.550     |\n| 1          | 1          | start         | 0.430     |\n| 1          | 1          | end           | 1.420     |\n| 2          | 0          | start         | 4.100     |\n| 2          | 0          | end           | 4.512     |\n| 2          | 1          | start         | 2.500     |\n| 2          | 1          | end           | 5.000     |\n+------------+------------+---------------+-----------+\nOutput: \n+------------+-----------------+\n| machine_id | processing_time |\n+------------+-----------------+\n| 0          | 0.894           |\n| 1          | 0.995           |\n| 2          | 1.456           |\n+------------+-----------------+\nExplanation: \nThere are 3 machines running 2 processes each.\nMachine 0's average time is ((1.520 - 0.712) + (4.120 - 3.140)) / 2 = 0.894\nMachine 1's average time is ((1.550 - 0.550) + (1.420 - 0.430)) / 2 = 0.995\nMachine 2's average time is ((4.512 - 4.100) + (5.000 - 2.500)) / 2 = 1.456\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 917, + "dislikes": 79, + "isLiked": null, + "similarQuestions": "[]", + "exampleTestcases": "{\"headers\":{\"Activity\":[\"machine_id\",\"process_id\",\"activity_type\",\"timestamp\"]},\"rows\":{\"Activity\":[[0,0,\"start\",0.712],[0,0,\"end\",1.52],[0,1,\"start\",3.14],[0,1,\"end\",4.12],[1,0,\"start\",0.55],[1,0,\"end\",1.55],[1,1,\"start\",0.43],[1,1,\"end\",1.42],[2,0,\"start\",4.1],[2,0,\"end\",4.512],[2,1,\"start\",2.5],[2,1,\"end\",5]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef get_average_time(activity: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"121.6K\", \"totalSubmission\": \"182K\", \"totalAcceptedRaw\": 121601, \"totalSubmissionRaw\": 181955, \"acRate\": \"66.8%\"}", + "hints": [], + "solution": { + "id": "2091", + "canSeeDetail": true, + "paidOnly": false, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "{\"headers\":{\"Activity\":[\"machine_id\",\"process_id\",\"activity_type\",\"timestamp\"]},\"rows\":{\"Activity\":[[0,0,\"start\",0.712],[0,0,\"end\",1.52],[0,1,\"start\",3.14],[0,1,\"end\",4.12],[1,0,\"start\",0.55],[1,0,\"end\",1.55],[1,1,\"start\",0.43],[1,1,\"end\",1.42],[2,0,\"start\",4.1],[2,0,\"end\",4.512],[2,1,\"start\",2.5],[2,1,\"end\",5]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Activity (machine_id int, process_id int, activity_type ENUM('start', 'end'), timestamp float)\"], \"mssql\": [\"create table Activity (machine_id int, process_id int, activity_type varchar(15) not null check(activity_type in ('start', 'end')), timestamp float)\"], \"oraclesql\": [\"create table Activity (machine_id int, process_id int, activity_type varchar(15) not null check(activity_type in ('start', 'end')), timestamp float)\"], \"database\": true, \"name\": \"get_average_time\", \"pythondata\": [\"Activity = pd.DataFrame([], columns=['machine_id', 'process_id', 'activity_type', 'timestamp']).astype({'machine_id':'Int64', 'process_id':'Int64', 'activity_type':'object', 'timestamp':'Float64'})\"], \"postgresql\": [\"Create table If Not Exists Activity (machine_id int, process_id int, activity_type VARCHAR(30) CHECK (activity_type IN ('start', 'end')), timestamp float)\\n\"], \"database_schema\": {\"Activity\": {\"machine_id\": \"INT\", \"process_id\": \"INT\", \"activity_type\": \"ENUM('start', 'end')\", \"timestamp\": \"FLOAT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Activity (machine_id int, process_id int, activity_type ENUM('start', 'end'), timestamp float)", + "Truncate table Activity", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('0', '0', 'start', '0.712')", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('0', '0', 'end', '1.52')", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('0', '1', 'start', '3.14')", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('0', '1', 'end', '4.12')", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('1', '0', 'start', '0.55')", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('1', '0', 'end', '1.55')", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('1', '1', 'start', '0.43')", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('1', '1', 'end', '1.42')", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('2', '0', 'start', '4.1')", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('2', '0', 'end', '4.512')", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('2', '1', 'start', '2.5')", + "insert into Activity (machine_id, process_id, activity_type, timestamp) values ('2', '1', 'end', '5')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/confirmation-rate.json b/leetcode/originData/confirmation-rate.json new file mode 100644 index 00000000..6e799004 --- /dev/null +++ b/leetcode/originData/confirmation-rate.json @@ -0,0 +1,97 @@ +{ + "data": { + "question": { + "questionId": "2087", + "questionFrontendId": "1934", + "boundTopicId": null, + "title": "Confirmation Rate", + "titleSlug": "confirmation-rate", + "content": "

Table: Signups

\n\n
\n+----------------+----------+\n| Column Name    | Type     |\n+----------------+----------+\n| user_id        | int      |\n| time_stamp     | datetime |\n+----------------+----------+\nuser_id is the column of unique values for this table.\nEach row contains information about the signup time for the user with ID user_id.\n
\n\n

 

\n\n

Table: Confirmations

\n\n
\n+----------------+----------+\n| Column Name    | Type     |\n+----------------+----------+\n| user_id        | int      |\n| time_stamp     | datetime |\n| action         | ENUM     |\n+----------------+----------+\n(user_id, time_stamp) is the primary key (combination of columns with unique values) for this table.\nuser_id is a foreign key (reference column) to the Signups table.\naction is an ENUM (category) of the type ('confirmed', 'timeout')\nEach row of this table indicates that the user with ID user_id requested a confirmation message at time_stamp and that confirmation message was either confirmed ('confirmed') or expired without confirming ('timeout').\n
\n\n

 

\n\n

The confirmation rate of a user is the number of 'confirmed' messages divided by the total number of requested confirmation messages. The confirmation rate of a user that did not request any confirmation messages is 0. Round the confirmation rate to two decimal places.

\n\n

Write a solution to find the confirmation rate of each user.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nSignups table:\n+---------+---------------------+\n| user_id | time_stamp          |\n+---------+---------------------+\n| 3       | 2020-03-21 10:16:13 |\n| 7       | 2020-01-04 13:57:59 |\n| 2       | 2020-07-29 23:09:44 |\n| 6       | 2020-12-09 10:39:37 |\n+---------+---------------------+\nConfirmations table:\n+---------+---------------------+-----------+\n| user_id | time_stamp          | action    |\n+---------+---------------------+-----------+\n| 3       | 2021-01-06 03:30:46 | timeout   |\n| 3       | 2021-07-14 14:00:00 | timeout   |\n| 7       | 2021-06-12 11:57:29 | confirmed |\n| 7       | 2021-06-13 12:58:28 | confirmed |\n| 7       | 2021-06-14 13:59:27 | confirmed |\n| 2       | 2021-01-22 00:00:00 | confirmed |\n| 2       | 2021-02-28 23:59:59 | timeout   |\n+---------+---------------------+-----------+\nOutput: \n+---------+-------------------+\n| user_id | confirmation_rate |\n+---------+-------------------+\n| 6       | 0.00              |\n| 3       | 0.00              |\n| 7       | 1.00              |\n| 2       | 0.50              |\n+---------+-------------------+\nExplanation: \nUser 6 did not request any confirmation messages. The confirmation rate is 0.\nUser 3 made 2 requests and both timed out. The confirmation rate is 0.\nUser 7 made 3 requests and all were confirmed. The confirmation rate is 1.\nUser 2 made 2 requests where one was confirmed and the other timed out. The confirmation rate is 1 / 2 = 0.5.\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 588, + "dislikes": 41, + "isLiked": null, + "similarQuestions": "[]", + "exampleTestcases": "{\"headers\": {\"Signups\": [\"user_id\", \"time_stamp\"], \"Confirmations\": [\"user_id\", \"time_stamp\", \"action\"]}, \"rows\": {\"Signups\": [[3, \"2020-03-21 10:16:13\"], [7, \"2020-01-04 13:57:59\"], [2, \"2020-07-29 23:09:44\"], [6, \"2020-12-09 10:39:37\"]], \"Confirmations\": [[3, \"2021-01-06 03:30:46\", \"timeout\"], [3, \"2021-07-14 14:00:00\", \"timeout\"], [7, \"2021-06-12 11:57:29\", \"confirmed\"], [7, \"2021-06-13 12:58:28\", \"confirmed\"], [7, \"2021-06-14 13:59:27\", \"confirmed\"], [2, \"2021-01-22 00:00:00\", \"confirmed\"], [2, \"2021-02-28 23:59:59\", \"timeout\"]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef confirmation_rate(signups: pd.DataFrame, confirmations: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"84.6K\", \"totalSubmission\": \"151K\", \"totalAcceptedRaw\": 84635, \"totalSubmissionRaw\": 151003, \"acRate\": \"56.0%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\": {\"Signups\": [\"user_id\", \"time_stamp\"], \"Confirmations\": [\"user_id\", \"time_stamp\", \"action\"]}, \"rows\": {\"Signups\": [[3, \"2020-03-21 10:16:13\"], [7, \"2020-01-04 13:57:59\"], [2, \"2020-07-29 23:09:44\"], [6, \"2020-12-09 10:39:37\"]], \"Confirmations\": [[3, \"2021-01-06 03:30:46\", \"timeout\"], [3, \"2021-07-14 14:00:00\", \"timeout\"], [7, \"2021-06-12 11:57:29\", \"confirmed\"], [7, \"2021-06-13 12:58:28\", \"confirmed\"], [7, \"2021-06-14 13:59:27\", \"confirmed\"], [2, \"2021-01-22 00:00:00\", \"confirmed\"], [2, \"2021-02-28 23:59:59\", \"timeout\"]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Signups (user_id int, time_stamp datetime)\", \"Create table If Not Exists Confirmations (user_id int, time_stamp datetime, action ENUM('confirmed','timeout'))\"], \"mssql\": [\"Create table Signups (user_id int, time_stamp datetime)\", \"Create table Confirmations (user_id int, time_stamp datetime, action VARCHAR(10) NOT NULL CHECK (action IN ('confirmed','timeout')))\"], \"oraclesql\": [\"Create table Signups (user_id int, time_stamp date)\", \"Create table Confirmations (user_id int, time_stamp date, action VARCHAR(10) NOT NULL CHECK (action IN ('confirmed','timeout')))\", \"ALTER SESSION SET nls_date_format='YYYY-MM-DD HH24:MI:SS'\"], \"database\": true, \"name\": \"confirmation_rate\", \"pythondata\": [\"Signups = pd.DataFrame([], columns=['user_id', 'time_stamp']).astype({'user_id':'Int64', 'time_stamp':'datetime64[ns]'})\", \"Confirmations = pd.DataFrame([], columns=['user_id', 'time_stamp', 'action']).astype({'user_id':'Int64', 'time_stamp':'datetime64[ns]', 'action':'object'})\"], \"postgresql\": [\"Create table If Not Exists Signups (user_id int, time_stamp timestamp)\\n\", \"Create table If Not Exists Confirmations (user_id int, time_stamp timestamp, action VARCHAR(30) CHECK (action IN ('confirmed','timeout')))\\n\"], \"database_schema\": {\"Signups\": {\"user_id\": \"INT\", \"time_stamp\": \"DATETIME\"}, \"Confirmations\": {\"user_id\": \"INT\", \"time_stamp\": \"DATETIME\", \"action\": \"ENUM('confirmed', 'timeout')\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Signups (user_id int, time_stamp datetime)", + "Create table If Not Exists Confirmations (user_id int, time_stamp datetime, action ENUM('confirmed','timeout'))", + "Truncate table Signups", + "insert into Signups (user_id, time_stamp) values ('3', '2020-03-21 10:16:13')", + "insert into Signups (user_id, time_stamp) values ('7', '2020-01-04 13:57:59')", + "insert into Signups (user_id, time_stamp) values ('2', '2020-07-29 23:09:44')", + "insert into Signups (user_id, time_stamp) values ('6', '2020-12-09 10:39:37')", + "Truncate table Confirmations", + "insert into Confirmations (user_id, time_stamp, action) values ('3', '2021-01-06 03:30:46', 'timeout')", + "insert into Confirmations (user_id, time_stamp, action) values ('3', '2021-07-14 14:00:00', 'timeout')", + "insert into Confirmations (user_id, time_stamp, action) values ('7', '2021-06-12 11:57:29', 'confirmed')", + "insert into Confirmations (user_id, time_stamp, action) values ('7', '2021-06-13 12:58:28', 'confirmed')", + "insert into Confirmations (user_id, time_stamp, action) values ('7', '2021-06-14 13:59:27', 'confirmed')", + "insert into Confirmations (user_id, time_stamp, action) values ('2', '2021-01-22 00:00:00', 'confirmed')", + "insert into Confirmations (user_id, time_stamp, action) values ('2', '2021-02-28 23:59:59', 'timeout')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/count-salary-categories.json b/leetcode/originData/count-salary-categories.json new file mode 100644 index 00000000..10af0703 --- /dev/null +++ b/leetcode/originData/count-salary-categories.json @@ -0,0 +1,95 @@ +{ + "data": { + "question": { + "questionId": "2057", + "questionFrontendId": "1907", + "boundTopicId": null, + "title": "Count Salary Categories", + "titleSlug": "count-salary-categories", + "content": "

Table: Accounts

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| account_id  | int  |\n| income      | int  |\n+-------------+------+\naccount_id is the primary key (column with unique values) for this table.\nEach row contains information about the monthly income for one bank account.\n
\n\n

 

\n\n

Write a solution to calculate the number of bank accounts for each salary category. The salary categories are:

\n\n
    \n\t
  • "Low Salary": All the salaries strictly less than $20000.
  • \n\t
  • "Average Salary": All the salaries in the inclusive range [$20000, $50000].
  • \n\t
  • "High Salary": All the salaries strictly greater than $50000.
  • \n
\n\n

The result table must contain all three categories. If there are no accounts in a category, return 0.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nAccounts table:\n+------------+--------+\n| account_id | income |\n+------------+--------+\n| 3          | 108939 |\n| 2          | 12747  |\n| 8          | 87709  |\n| 6          | 91796  |\n+------------+--------+\nOutput: \n+----------------+----------------+\n| category       | accounts_count |\n+----------------+----------------+\n| Low Salary     | 1              |\n| Average Salary | 0              |\n| High Salary    | 3              |\n+----------------+----------------+\nExplanation: \nLow Salary: Account 2.\nAverage Salary: No accounts.\nHigh Salary: Accounts 3, 6, and 8.\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 311, + "dislikes": 61, + "isLiked": null, + "similarQuestions": "[{\"title\": \"Create a Session Bar Chart\", \"titleSlug\": \"create-a-session-bar-chart\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]", + "exampleTestcases": "{\"headers\":{\"Accounts\":[\"account_id\",\"income\"]},\"rows\":{\"Accounts\":[[3,108939],[2,12747],[8,87709],[6,91796]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef count_salary_categories(accounts: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"47.8K\", \"totalSubmission\": \"82.7K\", \"totalAcceptedRaw\": 47831, \"totalSubmissionRaw\": 82718, \"acRate\": \"57.8%\"}", + "hints": [], + "solution": { + "id": "2021", + "canSeeDetail": false, + "paidOnly": true, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "{\"headers\":{\"Accounts\":[\"account_id\",\"income\"]},\"rows\":{\"Accounts\":[[3,108939],[2,12747],[8,87709],[6,91796]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Accounts (account_id int, income int)\"], \"mssql\": [\"Create table Accounts (account_id int, income int)\"], \"oraclesql\": [\"Create table Accounts (account_id int, income int)\"], \"database\": true, \"name\": \"count_salary_categories\", \"pythondata\": [\"Accounts = pd.DataFrame([], columns=['account_id', 'income']).astype({'account_id':'Int64', 'income':'Int64'})\"], \"postgresql\": [\"Create table If Not Exists Accounts (account_id int, income int)\"], \"database_schema\": {\"Accounts\": {\"account_id\": \"INT\", \"income\": \"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Accounts (account_id int, income int)", + "Truncate table Accounts", + "insert into Accounts (account_id, income) values ('3', '108939')", + "insert into Accounts (account_id, income) values ('2', '12747')", + "insert into Accounts (account_id, income) values ('8', '87709')", + "insert into Accounts (account_id, income) values ('6', '91796')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/customers-who-bought-all-products.json b/leetcode/originData/customers-who-bought-all-products.json new file mode 100644 index 00000000..8806ad5c --- /dev/null +++ b/leetcode/originData/customers-who-bought-all-products.json @@ -0,0 +1,100 @@ +{ + "data": { + "question": { + "questionId": "1135", + "questionFrontendId": "1045", + "boundTopicId": null, + "title": "Customers Who Bought All Products", + "titleSlug": "customers-who-bought-all-products", + "content": "

Table: Customer

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| customer_id | int     |\n| product_key | int     |\n+-------------+---------+\nThis table may contain duplicates rows. \ncustomer_id is not NULL.\nproduct_key is a foreign key (reference column) to Product table.\n
\n\n

 

\n\n

Table: Product

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| product_key | int     |\n+-------------+---------+\nproduct_key is the primary key (column with unique values) for this table.\n
\n\n

 

\n\n

Write a solution to report the customer ids from the Customer table that bought all the products in the Product table.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nCustomer table:\n+-------------+-------------+\n| customer_id | product_key |\n+-------------+-------------+\n| 1           | 5           |\n| 2           | 6           |\n| 3           | 5           |\n| 3           | 6           |\n| 1           | 6           |\n+-------------+-------------+\nProduct table:\n+-------------+\n| product_key |\n+-------------+\n| 5           |\n| 6           |\n+-------------+\nOutput: \n+-------------+\n| customer_id |\n+-------------+\n| 1           |\n| 3           |\n+-------------+\nExplanation: \nThe customers who bought all the products (5 and 6) are customers with IDs 1 and 3.\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 590, + "dislikes": 58, + "isLiked": null, + "similarQuestions": "[]", + "exampleTestcases": "{\"headers\":{\"Customer\":[\"customer_id\",\"product_key\"],\"Product\":[\"product_key\"]},\"rows\":{\"Customer\":[[1,5],[2,6],[3,5],[3,6],[1,6]],\"Product\":[[5],[6]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef find_customers(customer: pd.DataFrame, product: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"105.3K\", \"totalSubmission\": \"171.7K\", \"totalAcceptedRaw\": 105271, \"totalSubmissionRaw\": 171696, \"acRate\": \"61.3%\"}", + "hints": [], + "solution": { + "id": "1615", + "canSeeDetail": false, + "paidOnly": true, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "{\"headers\":{\"Customer\":[\"customer_id\",\"product_key\"],\"Product\":[\"product_key\"]},\"rows\":{\"Customer\":[[1,5],[2,6],[3,5],[3,6],[1,6]],\"Product\":[[5],[6]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Customer (customer_id int, product_key int)\", \"Create table Product (product_key int)\"], \"mssql\": [\"Create table Customer (customer_id int, product_key int)\", \"Create table Product (product_key int)\"], \"oraclesql\": [\"Create table Customer (customer_id int, product_key int)\", \"Create table Product (product_key int)\"], \"database\": true, \"name\": \"find_customers\", \"pythondata\": [\"Customer = pd.DataFrame([], columns=['customer_id', 'product_key']).astype({'customer_id':'Int64', 'product_key':'Int64'})\", \"Product = pd.DataFrame([], columns=['product_key']).astype({'product_key':'Int64'})\"], \"postgresql\": [\"Create table If Not Exists Customer (customer_id int, product_key int)\\n\", \"Create table Product (product_key int)\"], \"database_schema\": {\"Customer\": {\"customer_id\": \"INT\", \"product_key\": \"INT\"}, \"Product\": {\"product_key\": \"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Customer (customer_id int, product_key int)", + "Create table Product (product_key int)", + "Truncate table Customer", + "insert into Customer (customer_id, product_key) values ('1', '5')", + "insert into Customer (customer_id, product_key) values ('2', '6')", + "insert into Customer (customer_id, product_key) values ('3', '5')", + "insert into Customer (customer_id, product_key) values ('3', '6')", + "insert into Customer (customer_id, product_key) values ('1', '6')", + "Truncate table Product", + "insert into Product (product_key) values ('5')", + "insert into Product (product_key) values ('6')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/employee-bonus.json b/leetcode/originData/employee-bonus.json new file mode 100644 index 00000000..48ca78af --- /dev/null +++ b/leetcode/originData/employee-bonus.json @@ -0,0 +1,102 @@ +{ + "data": { + "question": { + "questionId": "577", + "questionFrontendId": "577", + "boundTopicId": null, + "title": "Employee Bonus", + "titleSlug": "employee-bonus", + "content": "

Table: Employee

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| empId       | int     |\n| name        | varchar |\n| supervisor  | int     |\n| salary      | int     |\n+-------------+---------+\nempId is the column with unique values for this table.\nEach row of this table indicates the name and the ID of an employee in addition to their salary and the id of their manager.\n
\n\n

 

\n\n

Table: Bonus

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| empId       | int  |\n| bonus       | int  |\n+-------------+------+\nempId is the column of unique values for this table.\nempId is a foreign key (reference column) to empId from the Employee table.\nEach row of this table contains the id of an employee and their respective bonus.\n
\n\n

 

\n\n

Write a solution to report the name and bonus amount of each employee with a bonus less than 1000.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nEmployee table:\n+-------+--------+------------+--------+\n| empId | name   | supervisor | salary |\n+-------+--------+------------+--------+\n| 3     | Brad   | null       | 4000   |\n| 1     | John   | 3          | 1000   |\n| 2     | Dan    | 3          | 2000   |\n| 4     | Thomas | 3          | 4000   |\n+-------+--------+------------+--------+\nBonus table:\n+-------+-------+\n| empId | bonus |\n+-------+-------+\n| 2     | 500   |\n| 4     | 2000  |\n+-------+-------+\nOutput: \n+------+-------+\n| name | bonus |\n+------+-------+\n| Brad | null  |\n| John | null  |\n| Dan  | 500   |\n+------+-------+\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 688, + "dislikes": 178, + "isLiked": null, + "similarQuestions": "[{\"title\": \"Combine Two Tables\", \"titleSlug\": \"combine-two-tables\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]", + "exampleTestcases": "{\"headers\":{\"Employee\":[\"empId\",\"name\",\"supervisor\",\"salary\"],\"Bonus\":[\"empId\",\"bonus\"]},\"rows\":{\"Employee\":[[3,\"Brad\",null,4000],[1,\"John\",3,1000],[2,\"Dan\",3,2000],[4,\"Thomas\",3,4000]],\"Bonus\":[[2,500],[4,2000]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef employee_bonus(employee: pd.DataFrame, bonus: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"214.5K\", \"totalSubmission\": \"290.8K\", \"totalAcceptedRaw\": 214505, \"totalSubmissionRaw\": 290845, \"acRate\": \"73.8%\"}", + "hints": [ + "If the EmpId in table Employee has no match in table Bonus, we consider that the corresponding bonus is null and null is smaller than 1000.", + "Inner join is the default join, we can solve the mismatching problem by using outer join." + ], + "solution": { + "id": "182", + "canSeeDetail": true, + "paidOnly": false, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "{\"headers\":{\"Employee\":[\"empId\",\"name\",\"supervisor\",\"salary\"],\"Bonus\":[\"empId\",\"bonus\"]},\"rows\":{\"Employee\":[[3,\"Brad\",null,4000],[1,\"John\",3,1000],[2,\"Dan\",3,2000],[4,\"Thomas\",3,4000]],\"Bonus\":[[2,500],[4,2000]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Employee (empId int, name varchar(255), supervisor int, salary int)\", \"Create table If Not Exists Bonus (empId int, bonus int)\"], \"mssql\": [\"Create table Employee (empId int, name varchar(255), supervisor int, salary int)\", \"Create table Bonus (empId int, bonus int)\"], \"oraclesql\": [\"Create table Employee (empId int, name varchar(255), supervisor int, salary int)\", \"Create table Bonus (empId int, bonus int)\"], \"database\": true, \"name\": \"employee_bonus\", \"manual\": false, \"pythondata\": [\"Employee = pd.DataFrame([], columns=['empId', 'name', 'supervisor', 'salary']).astype({'empId':'Int64', 'name':'object', 'supervisor':'Int64', 'salary':'Int64'})\", \"Bonus = pd.DataFrame([], columns=['empId', 'bonus']).astype({'empId':'Int64', 'bonus':'Int64'})\"], \"postgresql\": [\"Create table If Not Exists Employee (empId int, name varchar(255), supervisor int, salary int)\\n\", \"Create table If Not Exists Bonus (empId int, bonus int)\"], \"database_schema\": {\"Employee\": {\"empId\": \"INT\", \"name\": \"VARCHAR(255)\", \"supervisor\": \"INT\", \"salary\": \"INT\"}, \"Bonus\": {\"empId\": \"INT\", \"bonus\": \"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Employee (empId int, name varchar(255), supervisor int, salary int)", + "Create table If Not Exists Bonus (empId int, bonus int)", + "Truncate table Employee", + "insert into Employee (empId, name, supervisor, salary) values ('3', 'Brad', 'None', '4000')", + "insert into Employee (empId, name, supervisor, salary) values ('1', 'John', '3', '1000')", + "insert into Employee (empId, name, supervisor, salary) values ('2', 'Dan', '3', '2000')", + "insert into Employee (empId, name, supervisor, salary) values ('4', 'Thomas', '3', '4000')", + "Truncate table Bonus", + "insert into Bonus (empId, bonus) values ('2', '500')", + "insert into Bonus (empId, bonus) values ('4', '2000')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/employees-whose-manager-left-the-company.json b/leetcode/originData/employees-whose-manager-left-the-company.json new file mode 100644 index 00000000..e5e320f0 --- /dev/null +++ b/leetcode/originData/employees-whose-manager-left-the-company.json @@ -0,0 +1,90 @@ +{ + "data": { + "question": { + "questionId": "2127", + "questionFrontendId": "1978", + "boundTopicId": null, + "title": "Employees Whose Manager Left the Company", + "titleSlug": "employees-whose-manager-left-the-company", + "content": "

Table: Employees

\n\n
\n+-------------+----------+\n| Column Name | Type     |\n+-------------+----------+\n| employee_id | int      |\n| name        | varchar  |\n| manager_id  | int      |\n| salary      | int      |\n+-------------+----------+\nIn SQL, employee_id is the primary key for this table.\nThis table contains information about the employees, their salary, and the ID of their manager. Some employees do not have a manager (manager_id is null). \n
\n\n

 

\n\n

Find the IDs of the employees whose salary is strictly less than $30000 and whose manager left the company. When a manager leaves the company, their information is deleted from the Employees table, but the reports still have their manager_id set to the manager that left.

\n\n

Return the result table ordered by employee_id.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput:  \nEmployees table:\n+-------------+-----------+------------+--------+\n| employee_id | name      | manager_id | salary |\n+-------------+-----------+------------+--------+\n| 3           | Mila      | 9          | 60301  |\n| 12          | Antonella | null       | 31000  |\n| 13          | Emery     | null       | 67084  |\n| 1           | Kalel     | 11         | 21241  |\n| 9           | Mikaela   | null       | 50937  |\n| 11          | Joziah    | 6          | 28485  |\n+-------------+-----------+------------+--------+\nOutput: \n+-------------+\n| employee_id |\n+-------------+\n| 11          |\n+-------------+\n\nExplanation: \nThe employees with a salary less than $30000 are 1 (Kalel) and 11 (Joziah).\nKalel's manager is employee 11, who is still in the company (Joziah).\nJoziah's manager is employee 6, who left the company because there is no row for employee 6 as it was deleted.\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 271, + "dislikes": 22, + "isLiked": null, + "similarQuestions": "[]", + "exampleTestcases": "{\"headers\": {\"Employees\": [\"employee_id\", \"name\", \"manager_id\", \"salary\"]}, \"rows\": {\"Employees\": [[3, \"Mila\", 9, 60301], [12, \"Antonella\", null, 31000], [13, \"Emery\", null, 67084], [1, \"Kalel\", 11, 21241], [9, \"Mikaela\", null, 50937], [11, \"Joziah\", 6, 28485]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef find_employees(employees: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"52.6K\", \"totalSubmission\": \"111.9K\", \"totalAcceptedRaw\": 52557, \"totalSubmissionRaw\": 111928, \"acRate\": \"47.0%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\": {\"Employees\": [\"employee_id\", \"name\", \"manager_id\", \"salary\"]}, \"rows\": {\"Employees\": [[3, \"Mila\", 9, 60301], [12, \"Antonella\", null, 31000], [13, \"Emery\", null, 67084], [1, \"Kalel\", 11, 21241], [9, \"Mikaela\", null, 50937], [11, \"Joziah\", 6, 28485]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Employees (employee_id int, name varchar(20), manager_id int, salary int)\"], \"mssql\": [\"Create table Employees (employee_id int, name varchar(20), manager_id int, salary int)\"], \"oraclesql\": [\"Create table Employees (employee_id int, name varchar(20), manager_id int, salary int)\"], \"database\": true, \"name\": \"find_employees\", \"pythondata\": [\"Employees = pd.DataFrame([], columns=['employee_id', 'name', 'manager_id', 'salary']).astype({'employee_id':'Int64', 'name':'object', 'manager_id':'Int64', 'salary':'Int64'})\"], \"postgresql\": [\"Create table If Not Exists Employees (employee_id int, name varchar(20), manager_id int, salary int)\"], \"database_schema\": {\"Employees\": {\"employee_id\": \"INT\", \"name\": \"VARCHAR(20)\", \"manager_id\": \"INT\", \"salary\": \"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Employees (employee_id int, name varchar(20), manager_id int, salary int)", + "Truncate table Employees", + "insert into Employees (employee_id, name, manager_id, salary) values ('3', 'Mila', '9', '60301')", + "insert into Employees (employee_id, name, manager_id, salary) values ('12', 'Antonella', 'None', '31000')", + "insert into Employees (employee_id, name, manager_id, salary) values ('13', 'Emery', 'None', '67084')", + "insert into Employees (employee_id, name, manager_id, salary) values ('1', 'Kalel', '11', '21241')", + "insert into Employees (employee_id, name, manager_id, salary) values ('9', 'Mikaela', 'None', '50937')", + "insert into Employees (employee_id, name, manager_id, salary) values ('11', 'Joziah', '6', '28485')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/find-users-with-valid-e-mails.json b/leetcode/originData/find-users-with-valid-e-mails.json new file mode 100644 index 00000000..e099671c --- /dev/null +++ b/leetcode/originData/find-users-with-valid-e-mails.json @@ -0,0 +1,98 @@ +{ + "data": { + "question": { + "questionId": "1664", + "questionFrontendId": "1517", + "boundTopicId": null, + "title": "Find Users With Valid E-Mails", + "titleSlug": "find-users-with-valid-e-mails", + "content": "

Table: Users

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| name          | varchar |\n| mail          | varchar |\n+---------------+---------+\nuser_id is the primary key (column with unique values) for this table.\nThis table contains information of the users signed up in a website. Some e-mails are invalid.\n
\n\n

 

\n\n

Write a solution to find the users who have valid emails.

\n\n

A valid e-mail has a prefix name and a domain where:

\n\n
    \n\t
  • The prefix name is a string that may contain letters (upper or lower case), digits, underscore '_', period '.', and/or dash '-'. The prefix name must start with a letter.
  • \n\t
  • The domain is '@leetcode.com'.
  • \n
\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nUsers table:\n+---------+-----------+-------------------------+\n| user_id | name      | mail                    |\n+---------+-----------+-------------------------+\n| 1       | Winston   | winston@leetcode.com    |\n| 2       | Jonathan  | jonathanisgreat         |\n| 3       | Annabelle | bella-@leetcode.com     |\n| 4       | Sally     | sally.come@leetcode.com |\n| 5       | Marwan    | quarz#2020@leetcode.com |\n| 6       | David     | david69@gmail.com       |\n| 7       | Shapiro   | .shapo@leetcode.com     |\n+---------+-----------+-------------------------+\nOutput: \n+---------+-----------+-------------------------+\n| user_id | name      | mail                    |\n+---------+-----------+-------------------------+\n| 1       | Winston   | winston@leetcode.com    |\n| 3       | Annabelle | bella-@leetcode.com     |\n| 4       | Sally     | sally.come@leetcode.com |\n+---------+-----------+-------------------------+\nExplanation: \nThe mail of user 2 does not have a domain.\nThe mail of user 5 has the # sign which is not allowed.\nThe mail of user 6 does not have the leetcode domain.\nThe mail of user 7 starts with a period.\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 352, + "dislikes": 219, + "isLiked": null, + "similarQuestions": "[]", + "exampleTestcases": "{\"headers\":{\"Users\":[\"user_id\",\"name\",\"mail\"]},\"rows\":{\"Users\":[[1,\"Winston\",\"winston@leetcode.com\"],[2,\"Jonathan\",\"jonathanisgreat\"],[3,\"Annabelle\",\"bella-@leetcode.com\"],[4,\"Sally\",\"sally.come@leetcode.com\"],[5,\"Marwan\",\"quarz#2020@leetcode.com\"],[6,\"David\",\"david69@gmail.com\"],[7,\"Shapiro\",\".shapo@leetcode.com\"]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef valid_emails(users: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"66.2K\", \"totalSubmission\": \"140.9K\", \"totalAcceptedRaw\": 66211, \"totalSubmissionRaw\": 140892, \"acRate\": \"47.0%\"}", + "hints": [], + "solution": { + "id": "2011", + "canSeeDetail": false, + "paidOnly": true, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "{\"headers\":{\"Users\":[\"user_id\",\"name\",\"mail\"]},\"rows\":{\"Users\":[[1,\"Winston\",\"winston@leetcode.com\"],[2,\"Jonathan\",\"jonathanisgreat\"],[3,\"Annabelle\",\"bella-@leetcode.com\"],[4,\"Sally\",\"sally.come@leetcode.com\"],[5,\"Marwan\",\"quarz#2020@leetcode.com\"],[6,\"David\",\"david69@gmail.com\"],[7,\"Shapiro\",\".shapo@leetcode.com\"]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Users (user_id int, name varchar(30), mail varchar(50))\"], \"mssql\": [\"Create table Users (user_id int, name varchar(30), mail varchar(50))\"], \"oraclesql\": [\"Create table Users (user_id int, name varchar(30), mail varchar(50))\"], \"database\": true, \"name\": \"valid_emails\", \"pythondata\": [\"Users = pd.DataFrame([], columns=['user_id', 'name', 'mail']).astype({'user_id':'int64', 'name':'object', 'mail':'object'})\"], \"postgresql\": [\"\\nCreate table If Not Exists Users (user_id int, name varchar(30), mail varchar(50))\"], \"database_schema\": {\"Users\": {\"user_id\": \"INT\", \"name\": \"VARCHAR(30)\", \"mail\": \"VARCHAR(50)\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Users (user_id int, name varchar(30), mail varchar(50))", + "Truncate table Users", + "insert into Users (user_id, name, mail) values ('1', 'Winston', 'winston@leetcode.com')", + "insert into Users (user_id, name, mail) values ('2', 'Jonathan', 'jonathanisgreat')", + "insert into Users (user_id, name, mail) values ('3', 'Annabelle', 'bella-@leetcode.com')", + "insert into Users (user_id, name, mail) values ('4', 'Sally', 'sally.come@leetcode.com')", + "insert into Users (user_id, name, mail) values ('5', 'Marwan', 'quarz#2020@leetcode.com')", + "insert into Users (user_id, name, mail) values ('6', 'David', 'david69@gmail.com')", + "insert into Users (user_id, name, mail) values ('7', 'Shapiro', '.shapo@leetcode.com')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/friend-requests-ii-who-has-the-most-friends.json b/leetcode/originData/friend-requests-ii-who-has-the-most-friends.json new file mode 100644 index 00000000..930841f8 --- /dev/null +++ b/leetcode/originData/friend-requests-ii-who-has-the-most-friends.json @@ -0,0 +1,90 @@ +{ + "data": { + "question": { + "questionId": "602", + "questionFrontendId": "602", + "boundTopicId": null, + "title": "Friend Requests II: Who Has the Most Friends", + "titleSlug": "friend-requests-ii-who-has-the-most-friends", + "content": "

Table: RequestAccepted

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| requester_id   | int     |\n| accepter_id    | int     |\n| accept_date    | date    |\n+----------------+---------+\n(requester_id, accepter_id) is the primary key (combination of columns with unique values) for this table.\nThis table contains the ID of the user who sent the request, the ID of the user who received the request, and the date when the request was accepted.\n
\n\n

 

\n\n

Write a solution to find the people who have the most friends and the most friends number.

\n\n

The test cases are generated so that only one person has the most friends.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nRequestAccepted table:\n+--------------+-------------+-------------+\n| requester_id | accepter_id | accept_date |\n+--------------+-------------+-------------+\n| 1            | 2           | 2016/06/03  |\n| 1            | 3           | 2016/06/08  |\n| 2            | 3           | 2016/06/08  |\n| 3            | 4           | 2016/06/09  |\n+--------------+-------------+-------------+\nOutput: \n+----+-----+\n| id | num |\n+----+-----+\n| 3  | 3   |\n+----+-----+\nExplanation: \nThe person with id 3 is a friend of people 1, 2, and 4, so he has three friends in total, which is the most number than any others.\n
\n\n

 

\n

Follow up: In the real world, multiple people could have the same most number of friends. Could you find all these people in this case?

\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 537, + "dislikes": 96, + "isLiked": null, + "similarQuestions": "[]", + "exampleTestcases": "{\"headers\":{\"RequestAccepted\":[\"requester_id\",\"accepter_id\",\"accept_date\"]},\"rows\":{\"RequestAccepted\":[[1,2,\"2016/06/03\"],[1,3,\"2016/06/08\"],[2,3,\"2016/06/08\"],[3,4,\"2016/06/09\"]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef most_friends(request_accepted: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"91.7K\", \"totalSubmission\": \"161.3K\", \"totalAcceptedRaw\": 91690, \"totalSubmissionRaw\": 161334, \"acRate\": \"56.8%\"}", + "hints": [ + "Being friends is bidirectional. If you accept someone's adding friend request, both you and the other person will have one more friend." + ], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"RequestAccepted\":[\"requester_id\",\"accepter_id\",\"accept_date\"]},\"rows\":{\"RequestAccepted\":[[1,2,\"2016/06/03\"],[1,3,\"2016/06/08\"],[2,3,\"2016/06/08\"],[3,4,\"2016/06/09\"]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists RequestAccepted (requester_id int not null, accepter_id int null, accept_date date null)\"], \"mssql\": [\"Create table RequestAccepted (requester_id int not null, accepter_id int null, accept_date date null)\"], \"oraclesql\": [\"Create table RequestAccepted (requester_id int not null, accepter_id int null, accept_date date null)\", \"Alter SESSION set NLS_DATE_FORMAT = 'YYYY/MM/DD'\"], \"database\": true, \"name\": \"most_friends\", \"pythondata\": [\"RequestAccepted = pd.DataFrame([], columns=['requester_id', 'accepter_id', 'accept_date']).astype({'requester_id':'Int64', 'accepter_id':'Int64', 'accept_date':'datetime64[ns]'})\"], \"postgresql\": [\"\\nCreate table If Not Exists RequestAccepted (requester_id int not null, accepter_id int null, accept_date date null)\"], \"database_schema\": {\"RequestAccepted\": {\"requester_id\": \"INT\", \"accepter_id\": \"INT\", \"accept_date\": \"DATE\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists RequestAccepted (requester_id int not null, accepter_id int null, accept_date date null)", + "Truncate table RequestAccepted", + "insert into RequestAccepted (requester_id, accepter_id, accept_date) values ('1', '2', '2016/06/03')", + "insert into RequestAccepted (requester_id, accepter_id, accept_date) values ('1', '3', '2016/06/08')", + "insert into RequestAccepted (requester_id, accepter_id, accept_date) values ('2', '3', '2016/06/08')", + "insert into RequestAccepted (requester_id, accepter_id, accept_date) values ('3', '4', '2016/06/09')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/game-play-analysis-iv.json b/leetcode/originData/game-play-analysis-iv.json new file mode 100644 index 00000000..20c95adc --- /dev/null +++ b/leetcode/originData/game-play-analysis-iv.json @@ -0,0 +1,96 @@ +{ + "data": { + "question": { + "questionId": "1182", + "questionFrontendId": "550", + "boundTopicId": null, + "title": "Game Play Analysis IV", + "titleSlug": "game-play-analysis-iv", + "content": "

Table: Activity

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| player_id    | int     |\n| device_id    | int     |\n| event_date   | date    |\n| games_played | int     |\n+--------------+---------+\n(player_id, event_date) is the primary key (combination of columns with unique values) of this table.\nThis table shows the activity of players of some games.\nEach row is a record of a player who logged in and played a number of games (possibly 0) before logging out on someday using some device.\n
\n\n

 

\n\n

Write a solution to report the fraction of players that logged in again on the day after the day they first logged in, rounded to 2 decimal places. In other words, you need to count the number of players that logged in for at least two consecutive days starting from their first login date, then divide that number by the total number of players.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nActivity table:\n+-----------+-----------+------------+--------------+\n| player_id | device_id | event_date | games_played |\n+-----------+-----------+------------+--------------+\n| 1         | 2         | 2016-03-01 | 5            |\n| 1         | 2         | 2016-03-02 | 6            |\n| 2         | 3         | 2017-06-25 | 1            |\n| 3         | 1         | 2016-03-02 | 0            |\n| 3         | 4         | 2018-07-03 | 5            |\n+-----------+-----------+------------+--------------+\nOutput: \n+-----------+\n| fraction  |\n+-----------+\n| 0.33      |\n+-----------+\nExplanation: \nOnly the player with id 1 logged back in after the first day he had logged in so the answer is 1/3 = 0.33\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 709, + "dislikes": 148, + "isLiked": null, + "similarQuestions": "[{\"title\": \"Game Play Analysis III\", \"titleSlug\": \"game-play-analysis-iii\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Game Play Analysis V\", \"titleSlug\": \"game-play-analysis-v\", \"difficulty\": \"Hard\", \"translatedTitle\": null}]", + "exampleTestcases": "{\"headers\":{\"Activity\":[\"player_id\",\"device_id\",\"event_date\",\"games_played\"]},\"rows\":{\"Activity\":[[1,2,\"2016-03-01\",5],[1,2,\"2016-03-02\",6],[2,3,\"2017-06-25\",1],[3,1,\"2016-03-02\",0],[3,4,\"2018-07-03\",5]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef gameplay_analysis(activity: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"104.8K\", \"totalSubmission\": \"293.9K\", \"totalAcceptedRaw\": 104764, \"totalSubmissionRaw\": 293884, \"acRate\": \"35.6%\"}", + "hints": [], + "solution": { + "id": "1602", + "canSeeDetail": true, + "paidOnly": false, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "{\"headers\":{\"Activity\":[\"player_id\",\"device_id\",\"event_date\",\"games_played\"]},\"rows\":{\"Activity\":[[1,2,\"2016-03-01\",5],[1,2,\"2016-03-02\",6],[2,3,\"2017-06-25\",1],[3,1,\"2016-03-02\",0],[3,4,\"2018-07-03\",5]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Activity (player_id int, device_id int, event_date date, games_played int)\"], \"mssql\": [\"Create table Activity (player_id int, device_id int, event_date date, games_played int)\"], \"oraclesql\": [\"Create table Activity (player_id int, device_id int, event_date date, games_played int)\", \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"], \"database\": true, \"name\": \"gameplay_analysis\", \"pythondata\": [\"Activity = pd.DataFrame([], columns=['player_id', 'device_id', 'event_date', 'games_played']).astype({'player_id':'Int64', 'device_id':'Int64', 'event_date':'datetime64[ns]', 'games_played':'Int64'})\"], \"postgresql\": [\"\\nCreate table If Not Exists Activity (player_id int, device_id int, event_date date, games_played int)\"], \"database_schema\": {\"Activity\": {\"player_id\": \"INT\", \"device_id\": \"INT\", \"event_date\": \"DATE\", \"games_played\": \"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Activity (player_id int, device_id int, event_date date, games_played int)", + "Truncate table Activity", + "insert into Activity (player_id, device_id, event_date, games_played) values ('1', '2', '2016-03-01', '5')", + "insert into Activity (player_id, device_id, event_date, games_played) values ('1', '2', '2016-03-02', '6')", + "insert into Activity (player_id, device_id, event_date, games_played) values ('2', '3', '2017-06-25', '1')", + "insert into Activity (player_id, device_id, event_date, games_played) values ('3', '1', '2016-03-02', '0')", + "insert into Activity (player_id, device_id, event_date, games_played) values ('3', '4', '2018-07-03', '5')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/immediate-food-delivery-ii.json b/leetcode/originData/immediate-food-delivery-ii.json new file mode 100644 index 00000000..0a4acf70 --- /dev/null +++ b/leetcode/originData/immediate-food-delivery-ii.json @@ -0,0 +1,91 @@ +{ + "data": { + "question": { + "questionId": "1292", + "questionFrontendId": "1174", + "boundTopicId": null, + "title": "Immediate Food Delivery II", + "titleSlug": "immediate-food-delivery-ii", + "content": "

Table: Delivery

\n\n
\n+-----------------------------+---------+\n| Column Name                 | Type    |\n+-----------------------------+---------+\n| delivery_id                 | int     |\n| customer_id                 | int     |\n| order_date                  | date    |\n| customer_pref_delivery_date | date    |\n+-----------------------------+---------+\ndelivery_id is the column of unique values of this table.\nThe table holds information about food delivery to customers that make orders at some date and specify a preferred delivery date (on the same order date or after it).\n
\n\n

 

\n\n

If the customer's preferred delivery date is the same as the order date, then the order is called immediate; otherwise, it is called scheduled.

\n\n

The first order of a customer is the order with the earliest order date that the customer made. It is guaranteed that a customer has precisely one first order.

\n\n

Write a solution to find the percentage of immediate orders in the first orders of all customers, rounded to 2 decimal places.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nDelivery table:\n+-------------+-------------+------------+-----------------------------+\n| delivery_id | customer_id | order_date | customer_pref_delivery_date |\n+-------------+-------------+------------+-----------------------------+\n| 1           | 1           | 2019-08-01 | 2019-08-02                  |\n| 2           | 2           | 2019-08-02 | 2019-08-02                  |\n| 3           | 1           | 2019-08-11 | 2019-08-12                  |\n| 4           | 3           | 2019-08-24 | 2019-08-24                  |\n| 5           | 3           | 2019-08-21 | 2019-08-22                  |\n| 6           | 2           | 2019-08-11 | 2019-08-13                  |\n| 7           | 4           | 2019-08-09 | 2019-08-09                  |\n+-------------+-------------+------------+-----------------------------+\nOutput: \n+----------------------+\n| immediate_percentage |\n+----------------------+\n| 50.00                |\n+----------------------+\nExplanation: \nThe customer id 1 has a first order with delivery id 1 and it is scheduled.\nThe customer id 2 has a first order with delivery id 2 and it is immediate.\nThe customer id 3 has a first order with delivery id 5 and it is scheduled.\nThe customer id 4 has a first order with delivery id 7 and it is immediate.\nHence, half the customers have immediate first orders.\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 523, + "dislikes": 89, + "isLiked": null, + "similarQuestions": "[]", + "exampleTestcases": "{\"headers\":{\"Delivery\":[\"delivery_id\",\"customer_id\",\"order_date\",\"customer_pref_delivery_date\"]},\"rows\":{\"Delivery\":[[1,1,\"2019-08-01\",\"2019-08-02\"],[2,2,\"2019-08-02\",\"2019-08-02\"],[3,1,\"2019-08-11\",\"2019-08-12\"],[4,3,\"2019-08-24\",\"2019-08-24\"],[5,3,\"2019-08-21\",\"2019-08-22\"],[6,2,\"2019-08-11\",\"2019-08-13\"],[7,4,\"2019-08-09\",\"2019-08-09\"]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef immediate_food_delivery(delivery: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"80.5K\", \"totalSubmission\": \"158.4K\", \"totalAcceptedRaw\": 80457, \"totalSubmissionRaw\": 158366, \"acRate\": \"50.8%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Delivery\":[\"delivery_id\",\"customer_id\",\"order_date\",\"customer_pref_delivery_date\"]},\"rows\":{\"Delivery\":[[1,1,\"2019-08-01\",\"2019-08-02\"],[2,2,\"2019-08-02\",\"2019-08-02\"],[3,1,\"2019-08-11\",\"2019-08-12\"],[4,3,\"2019-08-24\",\"2019-08-24\"],[5,3,\"2019-08-21\",\"2019-08-22\"],[6,2,\"2019-08-11\",\"2019-08-13\"],[7,4,\"2019-08-09\",\"2019-08-09\"]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date)\"], \"mssql\": [\"Create table Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date)\"], \"oraclesql\": [\"Create table Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date)\", \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"], \"database\": true, \"name\": \"immediate_food_delivery\", \"pythondata\": [\"Delivery = pd.DataFrame([], columns=['delivery_id', 'customer_id', 'order_date', 'customer_pref_delivery_date']).astype({'delivery_id':'Int64', 'customer_id':'Int64', 'order_date':'datetime64[ns]', 'customer_pref_delivery_date':'datetime64[ns]'})\"], \"postgresql\": [\"\\nCreate table If Not Exists Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date)\"], \"database_schema\": {\"Delivery\": {\"delivery_id\": \"INT\", \"customer_id\": \"INT\", \"order_date\": \"DATE\", \"customer_pref_delivery_date\": \"DATE\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Delivery (delivery_id int, customer_id int, order_date date, customer_pref_delivery_date date)", + "Truncate table Delivery", + "insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('1', '1', '2019-08-01', '2019-08-02')", + "insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('2', '2', '2019-08-02', '2019-08-02')", + "insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('3', '1', '2019-08-11', '2019-08-12')", + "insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('4', '3', '2019-08-24', '2019-08-24')", + "insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('5', '3', '2019-08-21', '2019-08-22')", + "insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('6', '2', '2019-08-11', '2019-08-13')", + "insert into Delivery (delivery_id, customer_id, order_date, customer_pref_delivery_date) values ('7', '4', '2019-08-09', '2019-08-09')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/invalid-tweets.json b/leetcode/originData/invalid-tweets.json new file mode 100644 index 00000000..d7a60591 --- /dev/null +++ b/leetcode/originData/invalid-tweets.json @@ -0,0 +1,93 @@ +{ + "data": { + "question": { + "questionId": "1827", + "questionFrontendId": "1683", + "boundTopicId": null, + "title": "Invalid Tweets", + "titleSlug": "invalid-tweets", + "content": "

Table: Tweets

\n\n
\n+----------------+---------+\n| Column Name    | Type    |\n+----------------+---------+\n| tweet_id       | int     |\n| content        | varchar |\n+----------------+---------+\ntweet_id is the primary key (column with unique values) for this table.\nThis table contains all the tweets in a social media app.\n
\n\n

 

\n\n

Write a solution to find the IDs of the invalid tweets. The tweet is invalid if the number of characters used in the content of the tweet is strictly greater than 15.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nTweets table:\n+----------+----------------------------------+\n| tweet_id | content                          |\n+----------+----------------------------------+\n| 1        | Vote for Biden                   |\n| 2        | Let us make America great again! |\n+----------+----------------------------------+\nOutput: \n+----------+\n| tweet_id |\n+----------+\n| 2        |\n+----------+\nExplanation: \nTweet 1 has length = 14. It is a valid tweet.\nTweet 2 has length = 32. It is an invalid tweet.\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 698, + "dislikes": 228, + "isLiked": null, + "similarQuestions": "[]", + "exampleTestcases": "{\"headers\":{\"Tweets\":[\"tweet_id\",\"content\"]},\"rows\":{\"Tweets\":[[1,\"Vote for Biden\"],[2,\"Let us make America great again!\"]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef invalid_tweets(tweets: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"236.5K\", \"totalSubmission\": \"279.6K\", \"totalAcceptedRaw\": 236486, \"totalSubmissionRaw\": 279634, \"acRate\": \"84.6%\"}", + "hints": [], + "solution": { + "id": "1940", + "canSeeDetail": false, + "paidOnly": true, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "{\"headers\":{\"Tweets\":[\"tweet_id\",\"content\"]},\"rows\":{\"Tweets\":[[1,\"Vote for Biden\"],[2,\"Let us make America great again!\"]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Tweets(tweet_id int, content varchar(50))\"], \"mssql\": [\"Create table Tweets(tweet_id int, content varchar(50))\"], \"oraclesql\": [\"Create table Tweets(tweet_id int, content varchar(50))\"], \"database\": true, \"name\": \"invalid_tweets\", \"pythondata\": [\"Tweets = pd.DataFrame([], columns=['tweet_id', 'content']).astype({'tweet_id':'Int64', 'content':'object'})\"], \"postgresql\": [\"Create table If Not Exists Tweets(tweet_id int, content varchar(50))\"], \"database_schema\": {\"Tweets\": {\"tweet_id\": \"INT\", \"content\": \"VARCHAR(50)\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Tweets(tweet_id int, content varchar(50))", + "Truncate table Tweets", + "insert into Tweets (tweet_id, content) values ('1', 'Vote for Biden')", + "insert into Tweets (tweet_id, content) values ('2', 'Let us make America great again!')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/investments-in-2016.json b/leetcode/originData/investments-in-2016.json new file mode 100644 index 00000000..1da72ebc --- /dev/null +++ b/leetcode/originData/investments-in-2016.json @@ -0,0 +1,97 @@ +{ + "data": { + "question": { + "questionId": "585", + "questionFrontendId": "585", + "boundTopicId": null, + "title": "Investments in 2016", + "titleSlug": "investments-in-2016", + "content": "

Table: Insurance

\n\n
\n+-------------+-------+\n| Column Name | Type  |\n+-------------+-------+\n| pid         | int   |\n| tiv_2015    | float |\n| tiv_2016    | float |\n| lat         | float |\n| lon         | float |\n+-------------+-------+\npid is the primary key (column with unique values) for this table.\nEach row of this table contains information about one policy where:\npid is the policyholder's policy ID.\ntiv_2015 is the total investment value in 2015 and tiv_2016 is the total investment value in 2016.\nlat is the latitude of the policy holder's city. It's guaranteed that lat is not NULL.\nlon is the longitude of the policy holder's city. It's guaranteed that lon is not NULL.\n
\n\n

 

\n\n

Write a solution to report the sum of all total investment values in 2016 tiv_2016, for all policyholders who:

\n\n
    \n\t
  • have the same tiv_2015 value as one or more other policyholders, and
  • \n\t
  • are not located in the same city as any other policyholder (i.e., the (lat, lon) attribute pairs must be unique).
  • \n
\n\n

Round tiv_2016 to two decimal places.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nInsurance table:\n+-----+----------+----------+-----+-----+\n| pid | tiv_2015 | tiv_2016 | lat | lon |\n+-----+----------+----------+-----+-----+\n| 1   | 10       | 5        | 10  | 10  |\n| 2   | 20       | 20       | 20  | 20  |\n| 3   | 10       | 30       | 20  | 20  |\n| 4   | 10       | 40       | 40  | 40  |\n+-----+----------+----------+-----+-----+\nOutput: \n+----------+\n| tiv_2016 |\n+----------+\n| 45.00    |\n+----------+\nExplanation: \nThe first record in the table, like the last record, meets both of the two criteria.\nThe tiv_2015 value 10 is the same as the third and fourth records, and its location is unique.\n\nThe second record does not meet any of the two criteria. Its tiv_2015 is not like any other policyholders and its location is the same as the third record, which makes the third record fail, too.\nSo, the result is the sum of tiv_2016 of the first and last record, which is 45.\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 450, + "dislikes": 398, + "isLiked": null, + "similarQuestions": "[]", + "exampleTestcases": "{\"headers\":{\"Insurance\":[\"pid\",\"tiv_2015\",\"tiv_2016\",\"lat\",\"lon\"]},\"rows\":{\"Insurance\":[[1,10,5,10,10],[2,20,20,20,20],[3,10,30,20,20],[4,10,40,40,40]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef find_investments(insurance: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"72.4K\", \"totalSubmission\": \"153.7K\", \"totalAcceptedRaw\": 72438, \"totalSubmissionRaw\": 153695, \"acRate\": \"47.1%\"}", + "hints": [ + "Make the (LAT, LON) a pair to represent the location information" + ], + "solution": { + "id": "130", + "canSeeDetail": false, + "paidOnly": true, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "{\"headers\":{\"Insurance\":[\"pid\",\"tiv_2015\",\"tiv_2016\",\"lat\",\"lon\"]},\"rows\":{\"Insurance\":[[1,10,5,10,10],[2,20,20,20,20],[3,10,30,20,20],[4,10,40,40,40]]}}", + "metaData": "{\"mysql\": [\"Create Table If Not Exists Insurance (pid int, tiv_2015 float, tiv_2016 float, lat float, lon float)\"], \"mssql\": [\"Create Table Insurance (pid int, tiv_2015 float, tiv_2016 float, lat float, lon float)\"], \"oraclesql\": [\"Create Table Insurance (pid int, tiv_2015 float, tiv_2016 float, lat float, lon float)\"], \"database\": true, \"name\": \"find_investments\", \"pythondata\": [\"Insurance = pd.DataFrame([], columns=['pid', 'tiv_2015', 'tiv_2016', 'lat', 'lon']).astype({'pid':'Int64', 'tiv_2015':'Float64', 'tiv_2016':'Float64', 'lat':'Float64', 'lon':'Float64'})\"], \"postgresql\": [\"\\nCreate Table If Not Exists Insurance (pid int, tiv_2015 float, tiv_2016 float, lat float, lon float)\"], \"database_schema\": {\"Insurance\": {\"pid\": \"INT\", \"tiv_2015\": \"FLOAT\", \"tiv_2016\": \"FLOAT\", \"lat\": \"FLOAT\", \"lon\": \"FLOAT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create Table If Not Exists Insurance (pid int, tiv_2015 float, tiv_2016 float, lat float, lon float)", + "Truncate table Insurance", + "insert into Insurance (pid, tiv_2015, tiv_2016, lat, lon) values ('1', '10', '5', '10', '10')", + "insert into Insurance (pid, tiv_2015, tiv_2016, lat, lon) values ('2', '20', '20', '20', '20')", + "insert into Insurance (pid, tiv_2015, tiv_2016, lat, lon) values ('3', '10', '30', '20', '20')", + "insert into Insurance (pid, tiv_2015, tiv_2016, lat, lon) values ('4', '10', '40', '40', '40')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/last-person-to-fit-in-the-bus.json b/leetcode/originData/last-person-to-fit-in-the-bus.json new file mode 100644 index 00000000..7ee1f514 --- /dev/null +++ b/leetcode/originData/last-person-to-fit-in-the-bus.json @@ -0,0 +1,90 @@ +{ + "data": { + "question": { + "questionId": "1327", + "questionFrontendId": "1204", + "boundTopicId": null, + "title": "Last Person to Fit in the Bus", + "titleSlug": "last-person-to-fit-in-the-bus", + "content": "

Table: Queue

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| person_id   | int     |\n| person_name | varchar |\n| weight      | int     |\n| turn        | int     |\n+-------------+---------+\nperson_id column contains unique values.\nThis table has the information about all people waiting for a bus.\nThe person_id and turn columns will contain all numbers from 1 to n, where n is the number of rows in the table.\nturn determines the order of which the people will board the bus, where turn=1 denotes the first person to board and turn=n denotes the last person to board.\nweight is the weight of the person in kilograms.\n
\n\n

 

\n\n

There is a queue of people waiting to board a bus. However, the bus has a weight limit of 1000 kilograms, so there may be some people who cannot board.

\n\n

Write a solution to find the person_name of the last person that can fit on the bus without exceeding the weight limit. The test cases are generated such that the first person does not exceed the weight limit.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nQueue table:\n+-----------+-------------+--------+------+\n| person_id | person_name | weight | turn |\n+-----------+-------------+--------+------+\n| 5         | Alice       | 250    | 1    |\n| 4         | Bob         | 175    | 5    |\n| 3         | Alex        | 350    | 2    |\n| 6         | John Cena   | 400    | 3    |\n| 1         | Winston     | 500    | 6    |\n| 2         | Marie       | 200    | 4    |\n+-----------+-------------+--------+------+\nOutput: \n+-------------+\n| person_name |\n+-------------+\n| John Cena   |\n+-------------+\nExplanation: The folowing table is ordered by the turn for simplicity.\n+------+----+-----------+--------+--------------+\n| Turn | ID | Name      | Weight | Total Weight |\n+------+----+-----------+--------+--------------+\n| 1    | 5  | Alice     | 250    | 250          |\n| 2    | 3  | Alex      | 350    | 600          |\n| 3    | 6  | John Cena | 400    | 1000         | (last person to board)\n| 4    | 2  | Marie     | 200    | 1200         | (cannot board)\n| 5    | 4  | Bob       | 175    | ___          |\n| 6    | 1  | Winston   | 500    | ___          |\n+------+----+-----------+--------+--------------+\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 564, + "dislikes": 25, + "isLiked": null, + "similarQuestions": "[{\"title\": \"Running Total for Different Genders\", \"titleSlug\": \"running-total-for-different-genders\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"The Number of Seniors and Juniors to Join the Company\", \"titleSlug\": \"the-number-of-seniors-and-juniors-to-join-the-company\", \"difficulty\": \"Hard\", \"translatedTitle\": null}, {\"title\": \"The Number of Seniors and Juniors to Join the Company II\", \"titleSlug\": \"the-number-of-seniors-and-juniors-to-join-the-company-ii\", \"difficulty\": \"Hard\", \"translatedTitle\": null}]", + "exampleTestcases": "{\"headers\":{\"Queue\":[\"person_id\",\"person_name\",\"weight\",\"turn\"]},\"rows\":{\"Queue\":[[5,\"Alice\",250,1],[4,\"Bob\",175,5],[3,\"Alex\",350,2],[6,\"John Cena\",400,3],[1,\"Winston\",500,6],[2,\"Marie\",200,4]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef last_passenger(queue: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"72.6K\", \"totalSubmission\": \"109.7K\", \"totalAcceptedRaw\": 72614, \"totalSubmissionRaw\": 109723, \"acRate\": \"66.2%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Queue\":[\"person_id\",\"person_name\",\"weight\",\"turn\"]},\"rows\":{\"Queue\":[[5,\"Alice\",250,1],[4,\"Bob\",175,5],[3,\"Alex\",350,2],[6,\"John Cena\",400,3],[1,\"Winston\",500,6],[2,\"Marie\",200,4]]}}", + "metaData": "{\"manual\": false, \"mysql\": [\"Create table If Not Exists Queue (person_id int, person_name varchar(30), weight int, turn int)\"], \"mssql\": [\"Create table Queue (person_id int, person_name varchar(30), weight int, turn int)\"], \"oraclesql\": [\"Create table Queue (person_id int, person_name varchar(30), weight int, turn int)\"], \"database\": true, \"name\": \"last_passenger\", \"pythondata\": [\"Queue = pd.DataFrame([], columns=['person_id', 'person_name', 'weight', 'turn']).astype({'person_id':'Int64', 'person_name':'object', 'weight':'Int64', 'turn':'Int64'})\"], \"postgresql\": [\"\\nCreate table If Not Exists Queue (person_id int, person_name varchar(30), weight int, turn int)\"], \"database_schema\": {\"Queue\": {\"person_id\": \"INT\", \"person_name\": \"VARCHAR(30)\", \"weight\": \"INT\", \"turn\": \"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Queue (person_id int, person_name varchar(30), weight int, turn int)", + "Truncate table Queue", + "insert into Queue (person_id, person_name, weight, turn) values ('5', 'Alice', '250', '1')", + "insert into Queue (person_id, person_name, weight, turn) values ('4', 'Bob', '175', '5')", + "insert into Queue (person_id, person_name, weight, turn) values ('3', 'Alex', '350', '2')", + "insert into Queue (person_id, person_name, weight, turn) values ('6', 'John Cena', '400', '3')", + "insert into Queue (person_id, person_name, weight, turn) values ('1', 'Winston', '500', '6')", + "insert into Queue (person_id, person_name, weight, turn) values ('2', 'Marie', '200', '4')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/lexicographically-smallest-equivalent-string.json b/leetcode/originData/lexicographically-smallest-equivalent-string.json new file mode 100644 index 00000000..85791341 --- /dev/null +++ b/leetcode/originData/lexicographically-smallest-equivalent-string.json @@ -0,0 +1,189 @@ +{ + "data": { + "question": { + "questionId": "1058", + "questionFrontendId": "1061", + "boundTopicId": null, + "title": "Lexicographically Smallest Equivalent String", + "titleSlug": "lexicographically-smallest-equivalent-string", + "content": "

You are given two strings of the same length s1 and s2 and a string baseStr.

\n\n

We say s1[i] and s2[i] are equivalent characters.

\n\n
    \n\t
  • For example, if s1 = "abc" and s2 = "cde", then we have 'a' == 'c', 'b' == 'd', and 'c' == 'e'.
  • \n
\n\n

Equivalent characters follow the usual rules of any equivalence relation:

\n\n
    \n\t
  • Reflexivity: 'a' == 'a'.
  • \n\t
  • Symmetry: 'a' == 'b' implies 'b' == 'a'.
  • \n\t
  • Transitivity: 'a' == 'b' and 'b' == 'c' implies 'a' == 'c'.
  • \n
\n\n

For example, given the equivalency information from s1 = "abc" and s2 = "cde", "acd" and "aab" are equivalent strings of baseStr = "eed", and "aab" is the lexicographically smallest equivalent string of baseStr.

\n\n

Return the lexicographically smallest equivalent string of baseStr by using the equivalency information from s1 and s2.

\n\n

 

\n

Example 1:

\n\n
\nInput: s1 = "parker", s2 = "morris", baseStr = "parser"\nOutput: "makkek"\nExplanation: Based on the equivalency information in s1 and s2, we can group their characters as [m,p], [a,o], [k,r,s], [e,i].\nThe characters in each group are equivalent and sorted in lexicographical order.\nSo the answer is "makkek".\n
\n\n

Example 2:

\n\n
\nInput: s1 = "hello", s2 = "world", baseStr = "hold"\nOutput: "hdld"\nExplanation: Based on the equivalency information in s1 and s2, we can group their characters as [h,w], [d,e,o], [l,r].\nSo only the second letter 'o' in baseStr is changed to 'd', the answer is "hdld".\n
\n\n

Example 3:

\n\n
\nInput: s1 = "leetcode", s2 = "programs", baseStr = "sourcecode"\nOutput: "aauaaaaada"\nExplanation: We group the equivalent characters in s1 and s2 as [a,o,e,r,s,c], [l,p], [g,t] and [d,m], thus all letters in baseStr except 'u' and 'd' are transformed to 'a', the answer is "aauaaaaada".\n
\n\n

 

\n

Constraints:

\n\n
    \n\t
  • 1 <= s1.length, s2.length, baseStr <= 1000
  • \n\t
  • s1.length == s2.length
  • \n\t
  • s1, s2, and baseStr consist of lowercase English letters.
  • \n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 2264, + "dislikes": 154, + "isLiked": null, + "similarQuestions": "[]", + "exampleTestcases": "\"parker\"\n\"morris\"\n\"parser\"\n\"hello\"\n\"world\"\n\"hold\"\n\"leetcode\"\n\"programs\"\n\"sourcecode\"", + "categoryTitle": "Algorithms", + "contributors": [], + "topicTags": [ + { + "name": "String", + "slug": "string", + "translatedName": null, + "__typename": "TopicTagNode" + }, + { + "name": "Union Find", + "slug": "union-find", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "C++", + "langSlug": "cpp", + "code": "class Solution {\npublic:\n string smallestEquivalentString(string s1, string s2, string baseStr) {\n \n }\n};", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Java", + "langSlug": "java", + "code": "class Solution {\n public String smallestEquivalentString(String s1, String s2, String baseStr) {\n \n }\n}", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Python", + "langSlug": "python", + "code": "class Solution(object):\n def smallestEquivalentString(self, s1, s2, baseStr):\n \"\"\"\n :type s1: str\n :type s2: str\n :type baseStr: str\n :rtype: str\n \"\"\"\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Python3", + "langSlug": "python3", + "code": "class Solution:\n def smallestEquivalentString(self, s1: str, s2: str, baseStr: str) -> str:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "C", + "langSlug": "c", + "code": "char* smallestEquivalentString(char* s1, char* s2, char* baseStr) {\n \n}", + "__typename": "CodeSnippetNode" + }, + { + "lang": "C#", + "langSlug": "csharp", + "code": "public class Solution {\n public string SmallestEquivalentString(string s1, string s2, string baseStr) {\n \n }\n}", + "__typename": "CodeSnippetNode" + }, + { + "lang": "JavaScript", + "langSlug": "javascript", + "code": "/**\n * @param {string} s1\n * @param {string} s2\n * @param {string} baseStr\n * @return {string}\n */\nvar smallestEquivalentString = function(s1, s2, baseStr) {\n \n};", + "__typename": "CodeSnippetNode" + }, + { + "lang": "TypeScript", + "langSlug": "typescript", + "code": "function smallestEquivalentString(s1: string, s2: string, baseStr: string): string {\n \n};", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PHP", + "langSlug": "php", + "code": "class Solution {\n\n /**\n * @param String $s1\n * @param String $s2\n * @param String $baseStr\n * @return String\n */\n function smallestEquivalentString($s1, $s2, $baseStr) {\n \n }\n}", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Swift", + "langSlug": "swift", + "code": "class Solution {\n func smallestEquivalentString(_ s1: String, _ s2: String, _ baseStr: String) -> String {\n \n }\n}", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Kotlin", + "langSlug": "kotlin", + "code": "class Solution {\n fun smallestEquivalentString(s1: String, s2: String, baseStr: String): String {\n \n }\n}", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Dart", + "langSlug": "dart", + "code": "class Solution {\n String smallestEquivalentString(String s1, String s2, String baseStr) {\n \n }\n}", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Go", + "langSlug": "golang", + "code": "func smallestEquivalentString(s1 string, s2 string, baseStr string) string {\n \n}", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Ruby", + "langSlug": "ruby", + "code": "# @param {String} s1\n# @param {String} s2\n# @param {String} base_str\n# @return {String}\ndef smallest_equivalent_string(s1, s2, base_str)\n \nend", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Scala", + "langSlug": "scala", + "code": "object Solution {\n def smallestEquivalentString(s1: String, s2: String, baseStr: String): String = {\n \n }\n}", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Rust", + "langSlug": "rust", + "code": "impl Solution {\n pub fn smallest_equivalent_string(s1: String, s2: String, base_str: String) -> String {\n \n }\n}", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Racket", + "langSlug": "racket", + "code": "(define/contract (smallest-equivalent-string s1 s2 baseStr)\n (-> string? string? string? string?)\n )", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Erlang", + "langSlug": "erlang", + "code": "-spec smallest_equivalent_string(S1 :: unicode:unicode_binary(), S2 :: unicode:unicode_binary(), BaseStr :: unicode:unicode_binary()) -> unicode:unicode_binary().\nsmallest_equivalent_string(S1, S2, BaseStr) ->\n .", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Elixir", + "langSlug": "elixir", + "code": "defmodule Solution do\n @spec smallest_equivalent_string(s1 :: String.t, s2 :: String.t, base_str :: String.t) :: String.t\n def smallest_equivalent_string(s1, s2, base_str) do\n \n end\nend", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"75.3K\", \"totalSubmission\": \"98.4K\", \"totalAcceptedRaw\": 75291, \"totalSubmissionRaw\": 98428, \"acRate\": \"76.5%\"}", + "hints": [ + "Model these equalities as edges of a graph.", + "Group each connected component of the graph and assign each node of this component to the node with the lowest lexicographically character.", + "Finally convert the string with the precalculated information." + ], + "solution": { + "id": "1626", + "canSeeDetail": false, + "paidOnly": true, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "\"parker\"\n\"morris\"\n\"parser\"", + "metaData": "{\n \"name\": \"smallestEquivalentString\",\n \"params\": [\n {\n \"name\": \"s1\",\n \"type\": \"string\"\n },\n {\n \"name\": \"s2\",\n \"type\": \"string\"\n },\n {\n \"name\": \"baseStr\",\n \"type\": \"string\"\n }\n ],\n \"return\": {\n \"type\": \"string\"\n }\n}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": true, + "envInfo": "{\"cpp\": [\"C++\", \"

Compiled with clang 11 using the latest C++ 20 standard.

\\r\\n\\r\\n

Your code is compiled with level two optimization (-O2). AddressSanitizer is also enabled to help detect out-of-bounds and use-after-free bugs.

\\r\\n\\r\\n

Most standard library headers are already included automatically for your convenience.

\"], \"java\": [\"Java\", \"

OpenJDK 17. Java 8 features such as lambda expressions and stream API can be used.

\\r\\n\\r\\n

Most standard library headers are already included automatically for your convenience.

\\r\\n

Includes Pair class from https://docs.oracle.com/javase/8/javafx/api/javafx/util/Pair.html.

\"], \"python\": [\"Python\", \"

Python 2.7.12.

\\r\\n\\r\\n

Most libraries are already imported automatically for your convenience, such as array, bisect, collections. If you need more libraries, you can import it yourself.

\\r\\n\\r\\n

For Map/TreeMap data structure, you may use sortedcontainers library.

\\r\\n\\r\\n

Note that Python 2.7 will not be maintained past 2020. For the latest Python, please choose Python3 instead.

\"], \"c\": [\"C\", \"

Compiled with gcc 8.2 using the gnu11 standard.

\\r\\n\\r\\n

Your code is compiled with level one optimization (-O1). AddressSanitizer is also enabled to help detect out-of-bounds and use-after-free bugs.

\\r\\n\\r\\n

Most standard library headers are already included automatically for your convenience.

\\r\\n\\r\\n

For hash table operations, you may use uthash. \\\"uthash.h\\\" is included by default. Below are some examples:

\\r\\n\\r\\n

1. Adding an item to a hash.\\r\\n

\\r\\nstruct hash_entry {\\r\\n    int id;            /* we'll use this field as the key */\\r\\n    char name[10];\\r\\n    UT_hash_handle hh; /* makes this structure hashable */\\r\\n};\\r\\n\\r\\nstruct hash_entry *users = NULL;\\r\\n\\r\\nvoid add_user(struct hash_entry *s) {\\r\\n    HASH_ADD_INT(users, id, s);\\r\\n}\\r\\n
\\r\\n

\\r\\n\\r\\n

2. Looking up an item in a hash:\\r\\n

\\r\\nstruct hash_entry *find_user(int user_id) {\\r\\n    struct hash_entry *s;\\r\\n    HASH_FIND_INT(users, &user_id, s);\\r\\n    return s;\\r\\n}\\r\\n
\\r\\n

\\r\\n\\r\\n

3. Deleting an item in a hash:\\r\\n

\\r\\nvoid delete_user(struct hash_entry *user) {\\r\\n    HASH_DEL(users, user);  \\r\\n}\\r\\n
\\r\\n

\"], \"csharp\": [\"C#\", \"

C# 10 with .NET 6 runtime

\"], \"javascript\": [\"JavaScript\", \"

Node.js 16.13.2.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES6 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\\r\\n\\r\\n

For Priority Queue / Queue data structures, you may use 5.3.0 version of datastructures-js/priority-queue and 4.2.1 version of datastructures-js/queue.

\"], \"ruby\": [\"Ruby\", \"

Ruby 3.1

\\r\\n\\r\\n

Some common data structure implementations are provided in the Algorithms module: https://www.rubydoc.info/github/kanwei/algorithms/Algorithms

\"], \"swift\": [\"Swift\", \"

Swift 5.5.2.

\"], \"golang\": [\"Go\", \"

Go 1.21

\\r\\n

Support https://godoc.org/github.com/emirpasic/gods@v1.18.1 library.

\"], \"python3\": [\"Python3\", \"

Python 3.10.

\\r\\n\\r\\n

Most libraries are already imported automatically for your convenience, such as array, bisect, collections. If you need more libraries, you can import it yourself.

\\r\\n\\r\\n

For Map/TreeMap data structure, you may use sortedcontainers library.

\"], \"scala\": [\"Scala\", \"

Scala 2.13.7.

\"], \"kotlin\": [\"Kotlin\", \"

Kotlin 1.9.0.

\"], \"rust\": [\"Rust\", \"

Rust 1.58.1

\\r\\n\\r\\n

Supports rand v0.6\\u00a0from crates.io

\"], \"php\": [\"PHP\", \"

PHP 8.1.

\\r\\n

With bcmath module

\"], \"typescript\": [\"Typescript\", \"

TypeScript 5.1.6, Node.js 16.13.2.

\\r\\n\\r\\n

Your code is run with --harmony flag, enabling new ES2022 features.

\\r\\n\\r\\n

lodash.js library is included by default.

\"], \"racket\": [\"Racket\", \"

Run with Racket 8.3.

\"], \"erlang\": [\"Erlang\", \"Erlang/OTP 25.0\"], \"elixir\": [\"Elixir\", \"Elixir 1.13.4 with Erlang/OTP 25.0\"], \"dart\": [\"Dart\", \"

Dart 2.17.3

\\r\\n\\r\\n

Your code will be run directly without compiling

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": { + "id": "1198", + "date": "2023-01-14", + "incompleteChallengeCount": 0, + "streakCount": 0, + "type": "DAILY", + "__typename": "ChallengeQuestionNode" + }, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/list-the-products-ordered-in-a-period.json b/leetcode/originData/list-the-products-ordered-in-a-period.json new file mode 100644 index 00000000..c1fde209 --- /dev/null +++ b/leetcode/originData/list-the-products-ordered-in-a-period.json @@ -0,0 +1,103 @@ +{ + "data": { + "question": { + "questionId": "1462", + "questionFrontendId": "1327", + "boundTopicId": null, + "title": "List the Products Ordered in a Period", + "titleSlug": "list-the-products-ordered-in-a-period", + "content": "

Table: Products

\n\n
\n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| product_id       | int     |\n| product_name     | varchar |\n| product_category | varchar |\n+------------------+---------+\nproduct_id is the primary key (column with unique values) for this table.\nThis table contains data about the company's products.\n
\n\n

 

\n\n

Table: Orders

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| order_date    | date    |\n| unit          | int     |\n+---------------+---------+\nThis table may have duplicate rows.\nproduct_id is a foreign key (reference column) to the Products table.\nunit is the number of products ordered in order_date.\n
\n\n

 

\n\n

Write a solution to get the names of products that have at least 100 units ordered in February 2020 and their amount.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nProducts table:\n+-------------+-----------------------+------------------+\n| product_id  | product_name          | product_category |\n+-------------+-----------------------+------------------+\n| 1           | Leetcode Solutions    | Book             |\n| 2           | Jewels of Stringology | Book             |\n| 3           | HP                    | Laptop           |\n| 4           | Lenovo                | Laptop           |\n| 5           | Leetcode Kit          | T-shirt          |\n+-------------+-----------------------+------------------+\nOrders table:\n+--------------+--------------+----------+\n| product_id   | order_date   | unit     |\n+--------------+--------------+----------+\n| 1            | 2020-02-05   | 60       |\n| 1            | 2020-02-10   | 70       |\n| 2            | 2020-01-18   | 30       |\n| 2            | 2020-02-11   | 80       |\n| 3            | 2020-02-17   | 2        |\n| 3            | 2020-02-24   | 3        |\n| 4            | 2020-03-01   | 20       |\n| 4            | 2020-03-04   | 30       |\n| 4            | 2020-03-04   | 60       |\n| 5            | 2020-02-25   | 50       |\n| 5            | 2020-02-27   | 50       |\n| 5            | 2020-03-01   | 50       |\n+--------------+--------------+----------+\nOutput: \n+--------------------+---------+\n| product_name       | unit    |\n+--------------------+---------+\n| Leetcode Solutions | 130     |\n| Leetcode Kit       | 100     |\n+--------------------+---------+\nExplanation: \nProducts with product_id = 1 is ordered in February a total of (60 + 70) = 130.\nProducts with product_id = 2 is ordered in February a total of 80.\nProducts with product_id = 3 is ordered in February a total of (2 + 3) = 5.\nProducts with product_id = 4 was not ordered in February 2020.\nProducts with product_id = 5 is ordered in February a total of (50 + 50) = 100.\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 294, + "dislikes": 33, + "isLiked": null, + "similarQuestions": "[]", + "exampleTestcases": "{\"headers\": {\"Products\": [\"product_id\", \"product_name\", \"product_category\"], \"Orders\": [\"product_id\", \"order_date\", \"unit\"]}, \"rows\": {\"Products\": [[1, \"Leetcode Solutions\", \"Book\"], [2, \"Jewels of Stringology\", \"Book\"], [3, \"HP\", \"Laptop\"], [4, \"Lenovo\", \"Laptop\"], [5, \"Leetcode Kit\", \"T-shirt\"]], \"Orders\": [[1, \"2020-02-05\", 60], [1, \"2020-02-10\", 70], [2, \"2020-01-18\", 30], [2, \"2020-02-11\", 80], [3, \"2020-02-17\", 2], [3, \"2020-02-24\", 3], [4, \"2020-03-01\", 20], [4, \"2020-03-04\", 30], [4, \"2020-03-04\", 60], [5, \"2020-02-25\", 50], [5, \"2020-02-27\", 50], [5, \"2020-03-01\", 50]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef list_products(products: pd.DataFrame, orders: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"72.6K\", \"totalSubmission\": \"103.9K\", \"totalAcceptedRaw\": 72600, \"totalSubmissionRaw\": 103857, \"acRate\": \"69.9%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\": {\"Products\": [\"product_id\", \"product_name\", \"product_category\"], \"Orders\": [\"product_id\", \"order_date\", \"unit\"]}, \"rows\": {\"Products\": [[1, \"Leetcode Solutions\", \"Book\"], [2, \"Jewels of Stringology\", \"Book\"], [3, \"HP\", \"Laptop\"], [4, \"Lenovo\", \"Laptop\"], [5, \"Leetcode Kit\", \"T-shirt\"]], \"Orders\": [[1, \"2020-02-05\", 60], [1, \"2020-02-10\", 70], [2, \"2020-01-18\", 30], [2, \"2020-02-11\", 80], [3, \"2020-02-17\", 2], [3, \"2020-02-24\", 3], [4, \"2020-03-01\", 20], [4, \"2020-03-04\", 30], [4, \"2020-03-04\", 60], [5, \"2020-02-25\", 50], [5, \"2020-02-27\", 50], [5, \"2020-03-01\", 50]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Products (product_id int, product_name varchar(40), product_category varchar(40))\", \"Create table If Not Exists Orders (product_id int, order_date date, unit int)\"], \"mssql\": [\"Create table Products (product_id int, product_name varchar(40), product_category varchar(40))\\n\", \"Create table Orders (product_id int, order_date date, unit int)\"], \"oraclesql\": [\"Create table Products (product_id int, product_name varchar(40), product_category varchar(40))\", \"Create table Orders (product_id int, order_date date, unit int)\", \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"], \"database\": true, \"name\": \"list_products\", \"pythondata\": [\"Products = pd.DataFrame([], columns=['product_id', 'product_name', 'product_category']).astype({'product_id':'Int64', 'product_name':'object', 'product_category':'object'})\", \"Orders = pd.DataFrame([], columns=['product_id', 'order_date', 'unit']).astype({'product_id':'Int64', 'order_date':'datetime64[ns]', 'unit':'Int64'})\"], \"postgresql\": [\"\\nCreate table If Not Exists Products (product_id int, product_name varchar(40), product_category varchar(40))\", \"Create table If Not Exists Orders (product_id int, order_date date, unit int)\"], \"database_schema\": {\"Products\": {\"product_id\": \"INT\", \"product_name\": \"VARCHAR(40)\", \"product_category\": \"VARCHAR(40)\"}, \"Orders\": {\"product_id\": \"INT\", \"order_date\": \"DATE\", \"unit\": \"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Products (product_id int, product_name varchar(40), product_category varchar(40))", + "Create table If Not Exists Orders (product_id int, order_date date, unit int)", + "Truncate table Products", + "insert into Products (product_id, product_name, product_category) values ('1', 'Leetcode Solutions', 'Book')", + "insert into Products (product_id, product_name, product_category) values ('2', 'Jewels of Stringology', 'Book')", + "insert into Products (product_id, product_name, product_category) values ('3', 'HP', 'Laptop')", + "insert into Products (product_id, product_name, product_category) values ('4', 'Lenovo', 'Laptop')", + "insert into Products (product_id, product_name, product_category) values ('5', 'Leetcode Kit', 'T-shirt')", + "Truncate table Orders", + "insert into Orders (product_id, order_date, unit) values ('1', '2020-02-05', '60')", + "insert into Orders (product_id, order_date, unit) values ('1', '2020-02-10', '70')", + "insert into Orders (product_id, order_date, unit) values ('2', '2020-01-18', '30')", + "insert into Orders (product_id, order_date, unit) values ('2', '2020-02-11', '80')", + "insert into Orders (product_id, order_date, unit) values ('3', '2020-02-17', '2')", + "insert into Orders (product_id, order_date, unit) values ('3', '2020-02-24', '3')", + "insert into Orders (product_id, order_date, unit) values ('4', '2020-03-01', '20')", + "insert into Orders (product_id, order_date, unit) values ('4', '2020-03-04', '30')", + "insert into Orders (product_id, order_date, unit) values ('4', '2020-03-04', '60')", + "insert into Orders (product_id, order_date, unit) values ('5', '2020-02-25', '50')", + "insert into Orders (product_id, order_date, unit) values ('5', '2020-02-27', '50')", + "insert into Orders (product_id, order_date, unit) values ('5', '2020-03-01', '50')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/managers-with-at-least-5-direct-reports.json b/leetcode/originData/managers-with-at-least-5-direct-reports.json new file mode 100644 index 00000000..dba547f5 --- /dev/null +++ b/leetcode/originData/managers-with-at-least-5-direct-reports.json @@ -0,0 +1,102 @@ +{ + "data": { + "question": { + "questionId": "570", + "questionFrontendId": "570", + "boundTopicId": null, + "title": "Managers with at Least 5 Direct Reports", + "titleSlug": "managers-with-at-least-5-direct-reports", + "content": "

Table: Employee

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| id          | int     |\n| name        | varchar |\n| department  | varchar |\n| managerId   | int     |\n+-------------+---------+\nid is the primary key (column with unique values) for this table.\nEach row of this table indicates the name of an employee, their department, and the id of their manager.\nIf managerId is null, then the employee does not have a manager.\nNo employee will be the manager of themself.\n
\n\n

 

\n\n

Write a solution to find managers with at least five direct reports.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nEmployee table:\n+-----+-------+------------+-----------+\n| id  | name  | department | managerId |\n+-----+-------+------------+-----------+\n| 101 | John  | A          | null      |\n| 102 | Dan   | A          | 101       |\n| 103 | James | A          | 101       |\n| 104 | Amy   | A          | 101       |\n| 105 | Anne  | A          | 101       |\n| 106 | Ron   | B          | 101       |\n+-----+-------+------------+-----------+\nOutput: \n+------+\n| name |\n+------+\n| John |\n+------+\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 844, + "dislikes": 88, + "isLiked": null, + "similarQuestions": "[]", + "exampleTestcases": "{\"headers\": {\"Employee\": [\"id\", \"name\", \"department\", \"managerId\"]}, \"rows\": {\"Employee\": [[101, \"John\", \"A\", null],[102, \"Dan\", \"A\", 101], [103, \"James\", \"A\", 101], [104, \"Amy\", \"A\", 101], [105, \"Anne\", \"A\", 101], [106, \"Ron\", \"B\", 101]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef find_managers(employee: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"200.7K\", \"totalSubmission\": \"375.2K\", \"totalAcceptedRaw\": 200742, \"totalSubmissionRaw\": 375208, \"acRate\": \"53.5%\"}", + "hints": [ + "Try to get all the mangerIDs that have count bigger than 5", + "Use the last hint's result as a table and do join with origin table at id equals to managerId", + "This is a very good example to show the performance of SQL code. Try to work out other solutions and you may be surprised by running time difference.", + "If your solution uses 'IN' function and runs more than 5 seconds, try to optimize it by using 'JOIN' instead." + ], + "solution": { + "id": "209", + "canSeeDetail": false, + "paidOnly": true, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "{\"headers\": {\"Employee\": [\"id\", \"name\", \"department\", \"managerId\"]}, \"rows\": {\"Employee\": [[101, \"John\", \"A\", null],[102, \"Dan\", \"A\", 101], [103, \"James\", \"A\", 101], [104, \"Amy\", \"A\", 101], [105, \"Anne\", \"A\", 101], [106, \"Ron\", \"B\", 101]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Employee (id int, name varchar(255), department varchar(255), managerId int)\"], \"mssql\": [\"Create table Employee (id int, name varchar(255), department varchar(255), managerId int)\"], \"oraclesql\": [\"Create table Employee (id int, name varchar(255), department varchar(255), managerId int)\"], \"database\": true, \"name\": \"find_managers\", \"pythondata\": [\"Employee = pd.DataFrame([], columns=['id', 'name', 'department', 'managerId']).astype({'id':'Int64', 'name':'object', 'department':'object', 'managerId':'Int64'})\"], \"manual\": false, \"postgresql\": [\"\\nCreate table If Not Exists Employee (id int, name varchar(255), department varchar(255), managerId int)\"], \"database_schema\": {\"Employee\": {\"id\": \"INT\", \"name\": \"VARCHAR(255)\", \"department\": \"VARCHAR(255)\", \"managerId\": \"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Employee (id int, name varchar(255), department varchar(255), managerId int)", + "Truncate table Employee", + "insert into Employee (id, name, department, managerId) values ('101', 'John', 'A', 'None')", + "insert into Employee (id, name, department, managerId) values ('102', 'Dan', 'A', '101')", + "insert into Employee (id, name, department, managerId) values ('103', 'James', 'A', '101')", + "insert into Employee (id, name, department, managerId) values ('104', 'Amy', 'A', '101')", + "insert into Employee (id, name, department, managerId) values ('105', 'Anne', 'A', '101')", + "insert into Employee (id, name, department, managerId) values ('106', 'Ron', 'B', '101')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/monthly-transactions-i.json b/leetcode/originData/monthly-transactions-i.json new file mode 100644 index 00000000..6c836508 --- /dev/null +++ b/leetcode/originData/monthly-transactions-i.json @@ -0,0 +1,88 @@ +{ + "data": { + "question": { + "questionId": "1317", + "questionFrontendId": "1193", + "boundTopicId": null, + "title": "Monthly Transactions I", + "titleSlug": "monthly-transactions-i", + "content": "

Table: Transactions

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| country       | varchar |\n| state         | enum    |\n| amount        | int     |\n| trans_date    | date    |\n+---------------+---------+\nid is the primary key of this table.\nThe table has information about incoming transactions.\nThe state column is an enum of type ["approved", "declined"].\n
\n\n

 

\n\n

Write an SQL query to find for each month and country, the number of transactions and their total amount, the number of approved transactions and their total amount.

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nTransactions table:\n+------+---------+----------+--------+------------+\n| id   | country | state    | amount | trans_date |\n+------+---------+----------+--------+------------+\n| 121  | US      | approved | 1000   | 2018-12-18 |\n| 122  | US      | declined | 2000   | 2018-12-19 |\n| 123  | US      | approved | 2000   | 2019-01-01 |\n| 124  | DE      | approved | 2000   | 2019-01-07 |\n+------+---------+----------+--------+------------+\nOutput: \n+----------+---------+-------------+----------------+--------------------+-----------------------+\n| month    | country | trans_count | approved_count | trans_total_amount | approved_total_amount |\n+----------+---------+-------------+----------------+--------------------+-----------------------+\n| 2018-12  | US      | 2           | 1              | 3000               | 1000                  |\n| 2019-01  | US      | 1           | 1              | 2000               | 2000                  |\n| 2019-01  | DE      | 1           | 1              | 2000               | 2000                  |\n+----------+---------+-------------+----------------+--------------------+-----------------------+\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 614, + "dislikes": 46, + "isLiked": null, + "similarQuestions": "[{\"title\": \"Monthly Transactions II\", \"titleSlug\": \"monthly-transactions-ii\", \"difficulty\": \"Medium\", \"translatedTitle\": null}]", + "exampleTestcases": "{\"headers\":{\"Transactions\":[\"id\",\"country\",\"state\",\"amount\",\"trans_date\"]},\"rows\":{\"Transactions\":[[121,\"US\",\"approved\",1000,\"2018-12-18\"],[122,\"US\",\"declined\",2000,\"2018-12-19\"],[123,\"US\",\"approved\",2000,\"2019-01-01\"],[124,\"DE\",\"approved\",2000,\"2019-01-07\"]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef monthly_transactions(transactions: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"96.5K\", \"totalSubmission\": \"163.7K\", \"totalAcceptedRaw\": 96550, \"totalSubmissionRaw\": 163698, \"acRate\": \"59.0%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Transactions\":[\"id\",\"country\",\"state\",\"amount\",\"trans_date\"]},\"rows\":{\"Transactions\":[[121,\"US\",\"approved\",1000,\"2018-12-18\"],[122,\"US\",\"declined\",2000,\"2018-12-19\"],[123,\"US\",\"approved\",2000,\"2019-01-01\"],[124,\"DE\",\"approved\",2000,\"2019-01-07\"]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Transactions (id int, country varchar(4), state enum('approved', 'declined'), amount int, trans_date date)\"], \"mssql\": [\"Create table Transactions (id int, country varchar(4), state varchar(10) check(state in ('approved', 'declined')), amount int, trans_date date)\"], \"oraclesql\": [\"Create table Transactions (id int, country varchar(4), state varchar(10) check(state in ('approved', 'declined')), amount int, trans_date date)\", \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"], \"database\": true, \"name\": \"monthly_transactions\", \"pythondata\": [\"Transactions = pd.DataFrame([], columns=['id', 'country', 'state', 'amount', 'trans_date']).astype({'id':'Int64', 'country':'object', 'state':'object', 'amount':'Int64', 'trans_date':'datetime64[ns]'})\"], \"postgresql\": [\"Create table If Not Exists Transactions (id int, country varchar(4), state VARCHAR(30) CHECK (state IN ('approved', 'declined')), amount int, trans_date date)\\n\\n\"], \"database_schema\": {\"Transactions\": {\"id\": \"INT\", \"country\": \"VARCHAR(4)\", \"state\": \"ENUM('approved', 'declined')\", \"amount\": \"INT\", \"trans_date\": \"DATE\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Transactions (id int, country varchar(4), state enum('approved', 'declined'), amount int, trans_date date)", + "Truncate table Transactions", + "insert into Transactions (id, country, state, amount, trans_date) values ('121', 'US', 'approved', '1000', '2018-12-18')", + "insert into Transactions (id, country, state, amount, trans_date) values ('122', 'US', 'declined', '2000', '2018-12-19')", + "insert into Transactions (id, country, state, amount, trans_date) values ('123', 'US', 'approved', '2000', '2019-01-01')", + "insert into Transactions (id, country, state, amount, trans_date) values ('124', 'DE', 'approved', '2000', '2019-01-07')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/movie-rating.json b/leetcode/originData/movie-rating.json new file mode 100644 index 00000000..d0611200 --- /dev/null +++ b/leetcode/originData/movie-rating.json @@ -0,0 +1,104 @@ +{ + "data": { + "question": { + "questionId": "1480", + "questionFrontendId": "1341", + "boundTopicId": null, + "title": "Movie Rating", + "titleSlug": "movie-rating", + "content": "

Table: Movies

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| movie_id      | int     |\n| title         | varchar |\n+---------------+---------+\nmovie_id is the primary key (column with unique values) for this table.\ntitle is the name of the movie.\n
\n\n

 

\n\n

Table: Users

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| user_id       | int     |\n| name          | varchar |\n+---------------+---------+\nuser_id is the primary key (column with unique values) for this table.\n
\n\n

 

\n\n

Table: MovieRating

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| movie_id      | int     |\n| user_id       | int     |\n| rating        | int     |\n| created_at    | date    |\n+---------------+---------+\n(movie_id, user_id) is the primary key (column with unique values) for this table.\nThis table contains the rating of a movie by a user in their review.\ncreated_at is the user's review date. \n
\n\n

 

\n\n

Write a solution to:

\n\n
    \n\t
  • Find the name of the user who has rated the greatest number of movies. In case of a tie, return the lexicographically smaller user name.
  • \n\t
  • Find the movie name with the highest average rating in February 2020. In case of a tie, return the lexicographically smaller movie name.
  • \n
\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nMovies table:\n+-------------+--------------+\n| movie_id    |  title       |\n+-------------+--------------+\n| 1           | Avengers     |\n| 2           | Frozen 2     |\n| 3           | Joker        |\n+-------------+--------------+\nUsers table:\n+-------------+--------------+\n| user_id     |  name        |\n+-------------+--------------+\n| 1           | Daniel       |\n| 2           | Monica       |\n| 3           | Maria        |\n| 4           | James        |\n+-------------+--------------+\nMovieRating table:\n+-------------+--------------+--------------+-------------+\n| movie_id    | user_id      | rating       | created_at  |\n+-------------+--------------+--------------+-------------+\n| 1           | 1            | 3            | 2020-01-12  |\n| 1           | 2            | 4            | 2020-02-11  |\n| 1           | 3            | 2            | 2020-02-12  |\n| 1           | 4            | 1            | 2020-01-01  |\n| 2           | 1            | 5            | 2020-02-17  | \n| 2           | 2            | 2            | 2020-02-01  | \n| 2           | 3            | 2            | 2020-03-01  |\n| 3           | 1            | 3            | 2020-02-22  | \n| 3           | 2            | 4            | 2020-02-25  | \n+-------------+--------------+--------------+-------------+\nOutput: \n+--------------+\n| results      |\n+--------------+\n| Daniel       |\n| Frozen 2     |\n+--------------+\nExplanation: \nDaniel and Monica have rated 3 movies ("Avengers", "Frozen 2" and "Joker") but Daniel is smaller lexicographically.\nFrozen 2 and Joker have a rating average of 3.5 in February but Frozen 2 is smaller lexicographically.\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 418, + "dislikes": 148, + "isLiked": null, + "similarQuestions": "[]", + "exampleTestcases": "{\"headers\": {\"Movies\": [\"movie_id\", \"title\"], \"Users\": [\"user_id\", \"name\"], \"MovieRating\": [\"movie_id\", \"user_id\", \"rating\", \"created_at\"]}, \"rows\": {\"Movies\": [[1, \"Avengers\"], [2, \"Frozen 2\"], [3, \"Joker\"]], \"Users\": [[1, \"Daniel\"], [2, \"Monica\"], [3, \"Maria\"], [4, \"James\"]], \"MovieRating\": [[1, 1, 3, \"2020-01-12\"], [1, 2, 4, \"2020-02-11\"], [1, 3, 2, \"2020-02-12\"], [1, 4, 1, \"2020-01-01\"], [2, 1, 5, \"2020-02-17\"], [2, 2, 2, \"2020-02-01\"], [2, 3, 2, \"2020-03-01\"], [3, 1, 3, \"2020-02-22\"], [3, 2, 4, \"2020-02-25\"]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef movie_rating(movies: pd.DataFrame, users: pd.DataFrame, movie_rating: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"56.5K\", \"totalSubmission\": \"139K\", \"totalAcceptedRaw\": 56477, \"totalSubmissionRaw\": 139022, \"acRate\": \"40.6%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\": {\"Movies\": [\"movie_id\", \"title\"], \"Users\": [\"user_id\", \"name\"], \"MovieRating\": [\"movie_id\", \"user_id\", \"rating\", \"created_at\"]}, \"rows\": {\"Movies\": [[1, \"Avengers\"], [2, \"Frozen 2\"], [3, \"Joker\"]], \"Users\": [[1, \"Daniel\"], [2, \"Monica\"], [3, \"Maria\"], [4, \"James\"]], \"MovieRating\": [[1, 1, 3, \"2020-01-12\"], [1, 2, 4, \"2020-02-11\"], [1, 3, 2, \"2020-02-12\"], [1, 4, 1, \"2020-01-01\"], [2, 1, 5, \"2020-02-17\"], [2, 2, 2, \"2020-02-01\"], [2, 3, 2, \"2020-03-01\"], [3, 1, 3, \"2020-02-22\"], [3, 2, 4, \"2020-02-25\"]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Movies (movie_id int, title varchar(30))\", \"Create table If Not Exists Users (user_id int, name varchar(30))\", \"Create table If Not Exists MovieRating (movie_id int, user_id int, rating int, created_at date)\"], \"mssql\": [\"Create table Movies (movie_id int, title varchar(30))\", \"Create table Users (user_id int, name varchar(30))\", \"Create table MovieRating (movie_id int, user_id int, rating int, created_at date)\"], \"oraclesql\": [\"Create table Movies (movie_id int, title varchar(30))\", \"Create table Users (user_id int, name varchar(30))\", \"Create table MovieRating (movie_id int, user_id int, rating int, created_at date)\", \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"], \"database\": true, \"name\": \"movie_rating\", \"pythondata\": [\"Movies = pd.DataFrame([], columns=['movie_id', 'title']).astype({'movie_id':'Int64', 'title':'object'})\", \"Users = pd.DataFrame([], columns=['user_id', 'name']).astype({'user_id':'Int64', 'name':'object'})\", \"MovieRating = pd.DataFrame([], columns=['movie_id', 'user_id', 'rating', 'created_at']).astype({'movie_id':'Int64', 'user_id':'Int64', 'rating':'Int64', 'created_at':'datetime64[ns]'})\"], \"postgresql\": [\"\\nCreate table If Not Exists Movies (movie_id int, title varchar(30))\", \"Create table If Not Exists Users (user_id int, name varchar(30))\", \"Create table If Not Exists MovieRating (movie_id int, user_id int, rating int, created_at date)\"], \"database_schema\": {\"Movies\": {\"movie_id\": \"INT\", \"title\": \"VARCHAR(30)\"}, \"Users\": {\"user_id\": \"INT\", \"name\": \"VARCHAR(30)\"}, \"MovieRating\": {\"movie_id\": \"INT\", \"user_id\": \"INT\", \"rating\": \"INT\", \"created_at\": \"DATE\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Movies (movie_id int, title varchar(30))", + "Create table If Not Exists Users (user_id int, name varchar(30))", + "Create table If Not Exists MovieRating (movie_id int, user_id int, rating int, created_at date)", + "Truncate table Movies", + "insert into Movies (movie_id, title) values ('1', 'Avengers')", + "insert into Movies (movie_id, title) values ('2', 'Frozen 2')", + "insert into Movies (movie_id, title) values ('3', 'Joker')", + "Truncate table Users", + "insert into Users (user_id, name) values ('1', 'Daniel')", + "insert into Users (user_id, name) values ('2', 'Monica')", + "insert into Users (user_id, name) values ('3', 'Maria')", + "insert into Users (user_id, name) values ('4', 'James')", + "Truncate table MovieRating", + "insert into MovieRating (movie_id, user_id, rating, created_at) values ('1', '1', '3', '2020-01-12')", + "insert into MovieRating (movie_id, user_id, rating, created_at) values ('1', '2', '4', '2020-02-11')", + "insert into MovieRating (movie_id, user_id, rating, created_at) values ('1', '3', '2', '2020-02-12')", + "insert into MovieRating (movie_id, user_id, rating, created_at) values ('1', '4', '1', '2020-01-01')", + "insert into MovieRating (movie_id, user_id, rating, created_at) values ('2', '1', '5', '2020-02-17')", + "insert into MovieRating (movie_id, user_id, rating, created_at) values ('2', '2', '2', '2020-02-01')", + "insert into MovieRating (movie_id, user_id, rating, created_at) values ('2', '3', '2', '2020-03-01')", + "insert into MovieRating (movie_id, user_id, rating, created_at) values ('3', '1', '3', '2020-02-22')", + "insert into MovieRating (movie_id, user_id, rating, created_at) values ('3', '2', '4', '2020-02-25')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/number-of-unique-subjects-taught-by-each-teacher.json b/leetcode/originData/number-of-unique-subjects-taught-by-each-teacher.json new file mode 100644 index 00000000..8c898c59 --- /dev/null +++ b/leetcode/originData/number-of-unique-subjects-taught-by-each-teacher.json @@ -0,0 +1,98 @@ +{ + "data": { + "question": { + "questionId": "2495", + "questionFrontendId": "2356", + "boundTopicId": null, + "title": "Number of Unique Subjects Taught by Each Teacher", + "titleSlug": "number-of-unique-subjects-taught-by-each-teacher", + "content": "

Table: Teacher

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| teacher_id  | int  |\n| subject_id  | int  |\n| dept_id     | int  |\n+-------------+------+\n(subject_id, dept_id) is the primary key (combinations of columns with unique values) of this table.\nEach row in this table indicates that the teacher with teacher_id teaches the subject subject_id in the department dept_id.\n
\n\n

 

\n\n

Write a solution to calculate the number of unique subjects each teacher teaches in the university.

\n\n

Return the result table in any order.

\n\n

The result format is shown in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nTeacher table:\n+------------+------------+---------+\n| teacher_id | subject_id | dept_id |\n+------------+------------+---------+\n| 1          | 2          | 3       |\n| 1          | 2          | 4       |\n| 1          | 3          | 3       |\n| 2          | 1          | 1       |\n| 2          | 2          | 1       |\n| 2          | 3          | 1       |\n| 2          | 4          | 1       |\n+------------+------------+---------+\nOutput:  \n+------------+-----+\n| teacher_id | cnt |\n+------------+-----+\n| 1          | 2   |\n| 2          | 4   |\n+------------+-----+\nExplanation: \nTeacher 1:\n  - They teach subject 2 in departments 3 and 4.\n  - They teach subject 3 in department 3.\nTeacher 2:\n  - They teach subject 1 in department 1.\n  - They teach subject 2 in department 1.\n  - They teach subject 3 in department 1.\n  - They teach subject 4 in department 1.\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 322, + "dislikes": 19, + "isLiked": null, + "similarQuestions": "[]", + "exampleTestcases": "{\"headers\":{\"Teacher\":[\"teacher_id\",\"subject_id\",\"dept_id\"]},\"rows\":{\"Teacher\":[[1,2,3],[1,2,4],[1,3,3],[2,1,1],[2,2,1],[2,3,1],[2,4,1]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef count_unique_subjects(teacher: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"79.1K\", \"totalSubmission\": \"91.4K\", \"totalAcceptedRaw\": 79054, \"totalSubmissionRaw\": 91409, \"acRate\": \"86.5%\"}", + "hints": [], + "solution": { + "id": "2014", + "canSeeDetail": false, + "paidOnly": true, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "{\"headers\":{\"Teacher\":[\"teacher_id\",\"subject_id\",\"dept_id\"]},\"rows\":{\"Teacher\":[[1,2,3],[1,2,4],[1,3,3],[2,1,1],[2,2,1],[2,3,1],[2,4,1]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Teacher (teacher_id int, subject_id int, dept_id int)\"], \"mssql\": [\"Create table Teacher (teacher_id int, subject_id int, dept_id int)\"], \"oraclesql\": [\"Create table Teacher (teacher_id int, subject_id int, dept_id int)\"], \"database\": true, \"name\": \"count_unique_subjects\", \"pythondata\": [\"Teacher = pd.DataFrame([], columns=['teacher_id', 'subject_id', 'dept_id']).astype({'teacher_id':'Int64', 'subject_id':'Int64', 'dept_id':'Int64'})\"], \"postgresql\": [\"Create table If Not Exists Teacher (teacher_id int, subject_id int, dept_id int)\"], \"database_schema\": {\"Teacher\": {\"teacher_id\": \"INT\", \"subject_id\": \"INT\", \"dept_id\": \"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Teacher (teacher_id int, subject_id int, dept_id int)", + "Truncate table Teacher", + "insert into Teacher (teacher_id, subject_id, dept_id) values ('1', '2', '3')", + "insert into Teacher (teacher_id, subject_id, dept_id) values ('1', '2', '4')", + "insert into Teacher (teacher_id, subject_id, dept_id) values ('1', '3', '3')", + "insert into Teacher (teacher_id, subject_id, dept_id) values ('2', '1', '1')", + "insert into Teacher (teacher_id, subject_id, dept_id) values ('2', '2', '1')", + "insert into Teacher (teacher_id, subject_id, dept_id) values ('2', '3', '1')", + "insert into Teacher (teacher_id, subject_id, dept_id) values ('2', '4', '1')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/percentage-of-users-attended-a-contest.json b/leetcode/originData/percentage-of-users-attended-a-contest.json new file mode 100644 index 00000000..f1c9bf2f --- /dev/null +++ b/leetcode/originData/percentage-of-users-attended-a-contest.json @@ -0,0 +1,101 @@ +{ + "data": { + "question": { + "questionId": "1773", + "questionFrontendId": "1633", + "boundTopicId": null, + "title": "Percentage of Users Attended a Contest", + "titleSlug": "percentage-of-users-attended-a-contest", + "content": "

Table: Users

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| user_id     | int     |\n| user_name   | varchar |\n+-------------+---------+\nuser_id is the primary key (column with unique values) for this table.\nEach row of this table contains the name and the id of a user.\n
\n\n

 

\n\n

Table: Register

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| contest_id  | int     |\n| user_id     | int     |\n+-------------+---------+\n(contest_id, user_id) is the primary key (combination of columns with unique values) for this table.\nEach row of this table contains the id of a user and the contest they registered into.\n
\n\n

 

\n\n

Write a solution to find the percentage of the users registered in each contest rounded to two decimals.

\n\n

Return the result table ordered by percentage in descending order. In case of a tie, order it by contest_id in ascending order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nUsers table:\n+---------+-----------+\n| user_id | user_name |\n+---------+-----------+\n| 6       | Alice     |\n| 2       | Bob       |\n| 7       | Alex      |\n+---------+-----------+\nRegister table:\n+------------+---------+\n| contest_id | user_id |\n+------------+---------+\n| 215        | 6       |\n| 209        | 2       |\n| 208        | 2       |\n| 210        | 6       |\n| 208        | 6       |\n| 209        | 7       |\n| 209        | 6       |\n| 215        | 7       |\n| 208        | 7       |\n| 210        | 2       |\n| 207        | 2       |\n| 210        | 7       |\n+------------+---------+\nOutput: \n+------------+------------+\n| contest_id | percentage |\n+------------+------------+\n| 208        | 100.0      |\n| 209        | 100.0      |\n| 210        | 100.0      |\n| 215        | 66.67      |\n| 207        | 33.33      |\n+------------+------------+\nExplanation: \nAll the users registered in contests 208, 209, and 210. The percentage is 100% and we sort them in the answer table by contest_id in ascending order.\nAlice and Alex registered in contest 215 and the percentage is ((2/3) * 100) = 66.67%\nBob registered in contest 207 and the percentage is ((1/3) * 100) = 33.33%\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 483, + "dislikes": 46, + "isLiked": null, + "similarQuestions": "[{\"title\": \"Queries Quality and Percentage\", \"titleSlug\": \"queries-quality-and-percentage\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]", + "exampleTestcases": "{\"headers\":{\"Users\":[\"user_id\",\"user_name\"],\"Register\":[\"contest_id\",\"user_id\"]},\"rows\":{\"Users\":[[6,\"Alice\"],[2,\"Bob\"],[7,\"Alex\"]],\"Register\":[[215,6],[209,2],[208,2],[210,6],[208,6],[209,7],[209,6],[215,7],[208,7],[210,2],[207,2],[210,7]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef users_percentage(users: pd.DataFrame, register: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"90.7K\", \"totalSubmission\": \"160.8K\", \"totalAcceptedRaw\": 90686, \"totalSubmissionRaw\": 160840, \"acRate\": \"56.4%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Users\":[\"user_id\",\"user_name\"],\"Register\":[\"contest_id\",\"user_id\"]},\"rows\":{\"Users\":[[6,\"Alice\"],[2,\"Bob\"],[7,\"Alex\"]],\"Register\":[[215,6],[209,2],[208,2],[210,6],[208,6],[209,7],[209,6],[215,7],[208,7],[210,2],[207,2],[210,7]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Users (user_id int, user_name varchar(20))\", \"Create table If Not Exists Register (contest_id int, user_id int)\"], \"mssql\": [\"Create table Users (user_id int, user_name varchar(20))\", \"Create table Register (contest_id int, user_id int)\"], \"oraclesql\": [\"Create table Users (user_id int, user_name varchar(20))\", \"Create table Register (contest_id int, user_id int)\"], \"database\": true, \"name\": \"users_percentage\", \"pythondata\": [\"Users = pd.DataFrame([], columns=['user_id', 'user_name']).astype({'user_id':'Int64', 'user_name':'object'})\", \"Register = pd.DataFrame([], columns=['contest_id', 'user_id']).astype({'contest_id':'Int64', 'user_id':'Int64'})\"], \"postgresql\": [\"\\nCreate table If Not Exists Users (user_id int, user_name varchar(20))\\n\", \"Create table If Not Exists Register (contest_id int, user_id int)\"], \"database_schema\": {\"Users\": {\"user_id\": \"INT\", \"user_name\": \"VARCHAR(20)\"}, \"Register\": {\"contest_id\": \"INT\", \"user_id\": \"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Users (user_id int, user_name varchar(20))", + "Create table If Not Exists Register (contest_id int, user_id int)", + "Truncate table Users", + "insert into Users (user_id, user_name) values ('6', 'Alice')", + "insert into Users (user_id, user_name) values ('2', 'Bob')", + "insert into Users (user_id, user_name) values ('7', 'Alex')", + "Truncate table Register", + "insert into Register (contest_id, user_id) values ('215', '6')", + "insert into Register (contest_id, user_id) values ('209', '2')", + "insert into Register (contest_id, user_id) values ('208', '2')", + "insert into Register (contest_id, user_id) values ('210', '6')", + "insert into Register (contest_id, user_id) values ('208', '6')", + "insert into Register (contest_id, user_id) values ('209', '7')", + "insert into Register (contest_id, user_id) values ('209', '6')", + "insert into Register (contest_id, user_id) values ('215', '7')", + "insert into Register (contest_id, user_id) values ('208', '7')", + "insert into Register (contest_id, user_id) values ('210', '2')", + "insert into Register (contest_id, user_id) values ('207', '2')", + "insert into Register (contest_id, user_id) values ('210', '7')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/primary-department-for-each-employee.json b/leetcode/originData/primary-department-for-each-employee.json new file mode 100644 index 00000000..e9b80fb4 --- /dev/null +++ b/leetcode/originData/primary-department-for-each-employee.json @@ -0,0 +1,98 @@ +{ + "data": { + "question": { + "questionId": "1942", + "questionFrontendId": "1789", + "boundTopicId": null, + "title": "Primary Department for Each Employee", + "titleSlug": "primary-department-for-each-employee", + "content": "

Table: Employee

\n\n
\n+---------------+---------+\n| Column Name   |  Type   |\n+---------------+---------+\n| employee_id   | int     |\n| department_id | int     |\n| primary_flag  | varchar |\n+---------------+---------+\n(employee_id, department_id) is the primary key (combination of columns with unique values) for this table.\nemployee_id is the id of the employee.\ndepartment_id is the id of the department to which the employee belongs.\nprimary_flag is an ENUM (category) of type ('Y', 'N'). If the flag is 'Y', the department is the primary department for the employee. If the flag is 'N', the department is not the primary.\n
\n\n

 

\n\n

Employees can belong to multiple departments. When the employee joins other departments, they need to decide which department is their primary department. Note that when an employee belongs to only one department, their primary column is 'N'.

\n\n

Write a solution to report all the employees with their primary department. For employees who belong to one department, report their only department.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nEmployee table:\n+-------------+---------------+--------------+\n| employee_id | department_id | primary_flag |\n+-------------+---------------+--------------+\n| 1           | 1             | N            |\n| 2           | 1             | Y            |\n| 2           | 2             | N            |\n| 3           | 3             | N            |\n| 4           | 2             | N            |\n| 4           | 3             | Y            |\n| 4           | 4             | N            |\n+-------------+---------------+--------------+\nOutput: \n+-------------+---------------+\n| employee_id | department_id |\n+-------------+---------------+\n| 1           | 1             |\n| 2           | 1             |\n| 3           | 3             |\n| 4           | 3             |\n+-------------+---------------+\nExplanation: \n- The Primary department for employee 1 is 1.\n- The Primary department for employee 2 is 1.\n- The Primary department for employee 3 is 3.\n- The Primary department for employee 4 is 3.\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 346, + "dislikes": 151, + "isLiked": null, + "similarQuestions": "[]", + "exampleTestcases": "{\"headers\":{\"Employee\":[\"employee_id\",\"department_id\",\"primary_flag\"]},\"rows\":{\"Employee\":[[\"1\",\"1\",\"N\"],[\"2\",\"1\",\"Y\"],[\"2\",\"2\",\"N\"],[\"3\",\"3\",\"N\"],[\"4\",\"2\",\"N\"],[\"4\",\"3\",\"Y\"],[\"4\",\"4\",\"N\"]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef find_primary_department(employee: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"57.9K\", \"totalSubmission\": \"90K\", \"totalAcceptedRaw\": 57864, \"totalSubmissionRaw\": 90000, \"acRate\": \"64.3%\"}", + "hints": [], + "solution": { + "id": "2057", + "canSeeDetail": true, + "paidOnly": false, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "{\"headers\":{\"Employee\":[\"employee_id\",\"department_id\",\"primary_flag\"]},\"rows\":{\"Employee\":[[\"1\",\"1\",\"N\"],[\"2\",\"1\",\"Y\"],[\"2\",\"2\",\"N\"],[\"3\",\"3\",\"N\"],[\"4\",\"2\",\"N\"],[\"4\",\"3\",\"Y\"],[\"4\",\"4\",\"N\"]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Employee (employee_id int, department_id int, primary_flag ENUM('Y','N'))\"], \"mssql\": [\"Create table Employee (employee_id int, department_id int, primary_flag varchar(1) not null check(primary_flag in ('Y', 'N')))\"], \"oraclesql\": [\"Create table Employee (employee_id int, department_id int, primary_flag varchar(1) not null check(primary_flag in ('Y', 'N')))\"], \"database\": true, \"name\": \"find_primary_department\", \"pythondata\": [\"Employee = pd.DataFrame([], columns=['employee_id', 'department_id', 'primary_flag']).astype({'employee_id':'Int64', 'department_id':'Int64', 'primary_flag':'object'})\"], \"postgresql\": [\"Create table If Not Exists Employee (employee_id int, department_id int, primary_flag VARCHAR(30) CHECK (primary_flag IN ('Y','N')))\\n\"], \"database_schema\": {\"Employee\": {\"employee_id\": \"INT\", \"department_id\": \"INT\", \"primary_flag\": \"ENUM('Y', 'N')\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Employee (employee_id int, department_id int, primary_flag ENUM('Y','N'))", + "Truncate table Employee", + "insert into Employee (employee_id, department_id, primary_flag) values ('1', '1', 'N')", + "insert into Employee (employee_id, department_id, primary_flag) values ('2', '1', 'Y')", + "insert into Employee (employee_id, department_id, primary_flag) values ('2', '2', 'N')", + "insert into Employee (employee_id, department_id, primary_flag) values ('3', '3', 'N')", + "insert into Employee (employee_id, department_id, primary_flag) values ('4', '2', 'N')", + "insert into Employee (employee_id, department_id, primary_flag) values ('4', '3', 'Y')", + "insert into Employee (employee_id, department_id, primary_flag) values ('4', '4', 'N')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/product-price-at-a-given-date.json b/leetcode/originData/product-price-at-a-given-date.json new file mode 100644 index 00000000..6dd2690c --- /dev/null +++ b/leetcode/originData/product-price-at-a-given-date.json @@ -0,0 +1,97 @@ +{ + "data": { + "question": { + "questionId": "1278", + "questionFrontendId": "1164", + "boundTopicId": null, + "title": "Product Price at a Given Date", + "titleSlug": "product-price-at-a-given-date", + "content": "

Table: Products

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| product_id    | int     |\n| new_price     | int     |\n| change_date   | date    |\n+---------------+---------+\n(product_id, change_date) is the primary key (combination of columns with unique values) of this table.\nEach row of this table indicates that the price of some product was changed to a new price at some date.
\n\n

 

\n\n

Write a solution to find the prices of all products on 2019-08-16. Assume the price of all products before any change is 10.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nProducts table:\n+------------+-----------+-------------+\n| product_id | new_price | change_date |\n+------------+-----------+-------------+\n| 1          | 20        | 2019-08-14  |\n| 2          | 50        | 2019-08-14  |\n| 1          | 30        | 2019-08-15  |\n| 1          | 35        | 2019-08-16  |\n| 2          | 65        | 2019-08-17  |\n| 3          | 20        | 2019-08-18  |\n+------------+-----------+-------------+\nOutput: \n+------------+-------+\n| product_id | price |\n+------------+-------+\n| 2          | 50    |\n| 1          | 35    |\n| 3          | 10    |\n+------------+-------+\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 709, + "dislikes": 179, + "isLiked": null, + "similarQuestions": "[]", + "exampleTestcases": "{\"headers\":{\"Products\":[\"product_id\",\"new_price\",\"change_date\"]},\"rows\":{\"Products\":[[1,20,\"2019-08-14\"],[2,50,\"2019-08-14\"],[1,30,\"2019-08-15\"],[1,35,\"2019-08-16\"],[2,65,\"2019-08-17\"],[3,20,\"2019-08-18\"]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef price_at_given_date(products: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"77K\", \"totalSubmission\": \"137.8K\", \"totalAcceptedRaw\": 77042, \"totalSubmissionRaw\": 137775, \"acRate\": \"55.9%\"}", + "hints": [], + "solution": { + "id": "1621", + "canSeeDetail": true, + "paidOnly": false, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "{\"headers\":{\"Products\":[\"product_id\",\"new_price\",\"change_date\"]},\"rows\":{\"Products\":[[1,20,\"2019-08-14\"],[2,50,\"2019-08-14\"],[1,30,\"2019-08-15\"],[1,35,\"2019-08-16\"],[2,65,\"2019-08-17\"],[3,20,\"2019-08-18\"]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Products (product_id int, new_price int, change_date date)\"], \"mssql\": [\"Create table Products (product_id int, new_price int, change_date date)\"], \"oraclesql\": [\"Create table Products (product_id int, new_price int, change_date date)\", \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"], \"database\": true, \"name\": \"price_at_given_date\", \"pythondata\": [\"Products = pd.DataFrame([], columns=['product_id', 'new_price', 'change_date']).astype({'product_id':'Int64', 'new_price':'Int64', 'change_date':'datetime64[ns]'})\"], \"postgresql\": [\"\\nCreate table If Not Exists Products (product_id int, new_price int, change_date date)\"], \"database_schema\": {\"Products\": {\"product_id\": \"INT\", \"new_price\": \"INT\", \"change_date\": \"DATE\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Products (product_id int, new_price int, change_date date)", + "Truncate table Products", + "insert into Products (product_id, new_price, change_date) values ('1', '20', '2019-08-14')", + "insert into Products (product_id, new_price, change_date) values ('2', '50', '2019-08-14')", + "insert into Products (product_id, new_price, change_date) values ('1', '30', '2019-08-15')", + "insert into Products (product_id, new_price, change_date) values ('1', '35', '2019-08-16')", + "insert into Products (product_id, new_price, change_date) values ('2', '65', '2019-08-17')", + "insert into Products (product_id, new_price, change_date) values ('3', '20', '2019-08-18')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/product-sales-analysis-i.json b/leetcode/originData/product-sales-analysis-i.json new file mode 100644 index 00000000..8451973d --- /dev/null +++ b/leetcode/originData/product-sales-analysis-i.json @@ -0,0 +1,99 @@ +{ + "data": { + "question": { + "questionId": "1153", + "questionFrontendId": "1068", + "boundTopicId": null, + "title": "Product Sales Analysis I", + "titleSlug": "product-sales-analysis-i", + "content": "

Table: Sales

\n\n
\n+-------------+-------+\n| Column Name | Type  |\n+-------------+-------+\n| sale_id     | int   |\n| product_id  | int   |\n| year        | int   |\n| quantity    | int   |\n| price       | int   |\n+-------------+-------+\n(sale_id, year) is the primary key (combination of columns with unique values) of this table.\nproduct_id is a foreign key (reference column) to Product table.\nEach row of this table shows a sale on the product product_id in a certain year.\nNote that the price is per unit.\n
\n\n

 

\n\n

Table: Product

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n+--------------+---------+\nproduct_id is the primary key (column with unique values) of this table.\nEach row of this table indicates the product name of each product.\n
\n\n

 

\n\n

Write a solution to report the product_name, year, and price for each sale_id in the Sales table.

\n\n

Return the resulting table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nSales table:\n+---------+------------+------+----------+-------+\n| sale_id | product_id | year | quantity | price |\n+---------+------------+------+----------+-------+ \n| 1       | 100        | 2008 | 10       | 5000  |\n| 2       | 100        | 2009 | 12       | 5000  |\n| 7       | 200        | 2011 | 15       | 9000  |\n+---------+------------+------+----------+-------+\nProduct table:\n+------------+--------------+\n| product_id | product_name |\n+------------+--------------+\n| 100        | Nokia        |\n| 200        | Apple        |\n| 300        | Samsung      |\n+------------+--------------+\nOutput: \n+--------------+-------+-------+\n| product_name | year  | price |\n+--------------+-------+-------+\n| Nokia        | 2008  | 5000  |\n| Nokia        | 2009  | 5000  |\n| Apple        | 2011  | 9000  |\n+--------------+-------+-------+\nExplanation: \nFrom sale_id = 1, we can conclude that Nokia was sold for 5000 in the year 2008.\nFrom sale_id = 2, we can conclude that Nokia was sold for 5000 in the year 2009.\nFrom sale_id = 7, we can conclude that Apple was sold for 9000 in the year 2011.\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 620, + "dislikes": 195, + "isLiked": null, + "similarQuestions": "[{\"title\": \"Product Sales Analysis II\", \"titleSlug\": \"product-sales-analysis-ii\", \"difficulty\": \"Easy\", \"translatedTitle\": null}, {\"title\": \"Product Sales Analysis IV\", \"titleSlug\": \"product-sales-analysis-iv\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Product Sales Analysis V\", \"titleSlug\": \"product-sales-analysis-v\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]", + "exampleTestcases": "{\"headers\":{\"Sales\":[\"sale_id\",\"product_id\",\"year\",\"quantity\",\"price\"],\"Product\":[\"product_id\",\"product_name\"]},\"rows\":{\"Sales\":[[1,100,2008,10,5000],[2,100,2009,12,5000],[7,200,2011,15,9000]],\"Product\":[[100,\"Nokia\"],[200,\"Apple\"],[300,\"Samsung\"]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef sales_analysis(sales: pd.DataFrame, product: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"241K\", \"totalSubmission\": \"298.1K\", \"totalAcceptedRaw\": 241031, \"totalSubmissionRaw\": 298147, \"acRate\": \"80.8%\"}", + "hints": [], + "solution": { + "id": "2044", + "canSeeDetail": true, + "paidOnly": false, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "{\"headers\":{\"Sales\":[\"sale_id\",\"product_id\",\"year\",\"quantity\",\"price\"],\"Product\":[\"product_id\",\"product_name\"]},\"rows\":{\"Sales\":[[1,100,2008,10,5000],[2,100,2009,12,5000],[7,200,2011,15,9000]],\"Product\":[[100,\"Nokia\"],[200,\"Apple\"],[300,\"Samsung\"]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Sales (sale_id int, product_id int, year int, quantity int, price int)\", \"Create table If Not Exists Product (product_id int, product_name varchar(10))\"], \"mssql\": [\"Create table Sales (sale_id int, product_id int, year int, quantity int, price int)\", \"Create table Product (product_id int, product_name varchar(10))\"], \"oraclesql\": [\"Create table Sales (sale_id int, product_id int, year int, quantity int, price int)\", \"Create table Product (product_id int, product_name varchar(10))\"], \"database\": true, \"name\": \"sales_analysis\", \"pythondata\": [\"Sales = pd.DataFrame([], columns=['sale_id', 'product_id', 'year', 'quantity', 'price']).astype({'sale_id':'Int64', 'product_id':'Int64', 'year':'Int64', 'quantity':'Int64', 'price':'Int64'})\", \"Product = pd.DataFrame([], columns=['product_id', 'product_name']).astype({'product_id':'Int64', 'product_name':'object'})\"], \"postgresql\": [\"Create table If Not Exists Sales (sale_id int, product_id int, year int, quantity int, price int)\\n\", \"Create table If Not Exists Product (product_id int, product_name varchar(10))\"], \"database_schema\": {\"Sales\": {\"sale_id\": \"INT\", \"product_id\": \"INT\", \"year\": \"INT\", \"quantity\": \"INT\", \"price\": \"INT\"}, \"Product\": {\"product_id\": \"INT\", \"product_name\": \"VARCHAR(10)\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Sales (sale_id int, product_id int, year int, quantity int, price int)", + "Create table If Not Exists Product (product_id int, product_name varchar(10))", + "Truncate table Sales", + "insert into Sales (sale_id, product_id, year, quantity, price) values ('1', '100', '2008', '10', '5000')", + "insert into Sales (sale_id, product_id, year, quantity, price) values ('2', '100', '2009', '12', '5000')", + "insert into Sales (sale_id, product_id, year, quantity, price) values ('7', '200', '2011', '15', '9000')", + "Truncate table Product", + "insert into Product (product_id, product_name) values ('100', 'Nokia')", + "insert into Product (product_id, product_name) values ('200', 'Apple')", + "insert into Product (product_id, product_name) values ('300', 'Samsung')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/product-sales-analysis-iii.json b/leetcode/originData/product-sales-analysis-iii.json new file mode 100644 index 00000000..9e2c6576 --- /dev/null +++ b/leetcode/originData/product-sales-analysis-iii.json @@ -0,0 +1,99 @@ +{ + "data": { + "question": { + "questionId": "1155", + "questionFrontendId": "1070", + "boundTopicId": null, + "title": "Product Sales Analysis III", + "titleSlug": "product-sales-analysis-iii", + "content": "

Table: Sales

\n\n
\n+-------------+-------+\n| Column Name | Type  |\n+-------------+-------+\n| sale_id     | int   |\n| product_id  | int   |\n| year        | int   |\n| quantity    | int   |\n| price       | int   |\n+-------------+-------+\n(sale_id, year) is the primary key (combination of columns with unique values) of this table.\nproduct_id is a foreign key (reference column) to Product table.\nEach row of this table shows a sale on the product product_id in a certain year.\nNote that the price is per unit.\n
\n\n

 

\n\n

Table: Product

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| product_id   | int     |\n| product_name | varchar |\n+--------------+---------+\nproduct_id is the primary key (column with unique values) of this table.\nEach row of this table indicates the product name of each product.\n
\n\n

 

\n\n

Write a solution to select the product id, year, quantity, and price for the first year of every product sold.

\n\n

Return the resulting table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nSales table:\n+---------+------------+------+----------+-------+\n| sale_id | product_id | year | quantity | price |\n+---------+------------+------+----------+-------+ \n| 1       | 100        | 2008 | 10       | 5000  |\n| 2       | 100        | 2009 | 12       | 5000  |\n| 7       | 200        | 2011 | 15       | 9000  |\n+---------+------------+------+----------+-------+\nProduct table:\n+------------+--------------+\n| product_id | product_name |\n+------------+--------------+\n| 100        | Nokia        |\n| 200        | Apple        |\n| 300        | Samsung      |\n+------------+--------------+\nOutput: \n+------------+------------+----------+-------+\n| product_id | first_year | quantity | price |\n+------------+------------+----------+-------+ \n| 100        | 2008       | 10       | 5000  |\n| 200        | 2011       | 15       | 9000  |\n+------------+------------+----------+-------+\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 290, + "dislikes": 737, + "isLiked": null, + "similarQuestions": "[{\"title\": \"Product Sales Analysis II\", \"titleSlug\": \"product-sales-analysis-ii\", \"difficulty\": \"Easy\", \"translatedTitle\": null}, {\"title\": \"Product Sales Analysis IV\", \"titleSlug\": \"product-sales-analysis-iv\", \"difficulty\": \"Medium\", \"translatedTitle\": null}, {\"title\": \"Product Sales Analysis V\", \"titleSlug\": \"product-sales-analysis-v\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]", + "exampleTestcases": "{\"headers\":{\"Sales\":[\"sale_id\",\"product_id\",\"year\",\"quantity\",\"price\"],\"Product\":[\"product_id\",\"product_name\"]},\"rows\":{\"Sales\":[[1,100,2008,10,5000],[2,100,2009,12,5000],[7,200,2011,15,9000]],\"Product\":[[100,\"Nokia\"],[200,\"Apple\"],[300,\"Samsung\"]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef sales_analysis(sales: pd.DataFrame, product: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"86.9K\", \"totalSubmission\": \"202.6K\", \"totalAcceptedRaw\": 86898, \"totalSubmissionRaw\": 202639, \"acRate\": \"42.9%\"}", + "hints": [], + "solution": { + "id": "2133", + "canSeeDetail": true, + "paidOnly": false, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "{\"headers\":{\"Sales\":[\"sale_id\",\"product_id\",\"year\",\"quantity\",\"price\"],\"Product\":[\"product_id\",\"product_name\"]},\"rows\":{\"Sales\":[[1,100,2008,10,5000],[2,100,2009,12,5000],[7,200,2011,15,9000]],\"Product\":[[100,\"Nokia\"],[200,\"Apple\"],[300,\"Samsung\"]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Sales (sale_id int, product_id int, year int, quantity int, price int)\", \"Create table If Not Exists Product (product_id int, product_name varchar(10))\"], \"mssql\": [\"Create table Sales (sale_id int, product_id int, year int, quantity int, price int)\", \"Create table Product (product_id int, product_name varchar(10))\"], \"oraclesql\": [\"Create table Sales (sale_id int, product_id int, year int, quantity int, price int)\", \"Create table Product (product_id int, product_name varchar(10))\"], \"database\": true, \"name\": \"sales_analysis\", \"pythondata\": [\"Sales = pd.DataFrame([], columns=['sale_id', 'product_id', 'year', 'quantity', 'price']).astype({'sale_id':'Int64', 'product_id':'Int64', 'year':'Int64', 'quantity':'Int64', 'price':'Int64'})\", \"Product = pd.DataFrame([], columns=['product_id', 'product_name']).astype({'product_id':'Int64', 'product_name':'object'})\"], \"postgresql\": [\"Create table If Not Exists Sales (sale_id int, product_id int, year int, quantity int, price int)\\n\", \"Create table If Not Exists Product (product_id int, product_name varchar(10))\"], \"database_schema\": {\"Sales\": {\"sale_id\": \"INT\", \"product_id\": \"INT\", \"year\": \"INT\", \"quantity\": \"INT\", \"price\": \"INT\"}, \"Product\": {\"product_id\": \"INT\", \"product_name\": \"VARCHAR(10)\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Sales (sale_id int, product_id int, year int, quantity int, price int)", + "Create table If Not Exists Product (product_id int, product_name varchar(10))", + "Truncate table Sales", + "insert into Sales (sale_id, product_id, year, quantity, price) values ('1', '100', '2008', '10', '5000')", + "insert into Sales (sale_id, product_id, year, quantity, price) values ('2', '100', '2009', '12', '5000')", + "insert into Sales (sale_id, product_id, year, quantity, price) values ('7', '200', '2011', '15', '9000')", + "Truncate table Product", + "insert into Product (product_id, product_name) values ('100', 'Nokia')", + "insert into Product (product_id, product_name) values ('200', 'Apple')", + "insert into Product (product_id, product_name) values ('300', 'Samsung')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/project-employees-i.json b/leetcode/originData/project-employees-i.json new file mode 100644 index 00000000..b7b627fb --- /dev/null +++ b/leetcode/originData/project-employees-i.json @@ -0,0 +1,95 @@ +{ + "data": { + "question": { + "questionId": "1161", + "questionFrontendId": "1075", + "boundTopicId": null, + "title": "Project Employees I", + "titleSlug": "project-employees-i", + "content": "

Table: Project

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| project_id  | int     |\n| employee_id | int     |\n+-------------+---------+\n(project_id, employee_id) is the primary key of this table.\nemployee_id is a foreign key to Employee table.\nEach row of this table indicates that the employee with employee_id is working on the project with project_id.\n
\n\n

 

\n\n

Table: Employee

\n\n
\n+------------------+---------+\n| Column Name      | Type    |\n+------------------+---------+\n| employee_id      | int     |\n| name             | varchar |\n| experience_years | int     |\n+------------------+---------+\nemployee_id is the primary key of this table. It's guaranteed that experience_years is not NULL.\nEach row of this table contains information about one employee.\n
\n\n

 

\n\n

Write an SQL query that reports the average experience years of all the employees for each project, rounded to 2 digits.

\n\n

Return the result table in any order.

\n\n

The query result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nProject table:\n+-------------+-------------+\n| project_id  | employee_id |\n+-------------+-------------+\n| 1           | 1           |\n| 1           | 2           |\n| 1           | 3           |\n| 2           | 1           |\n| 2           | 4           |\n+-------------+-------------+\nEmployee table:\n+-------------+--------+------------------+\n| employee_id | name   | experience_years |\n+-------------+--------+------------------+\n| 1           | Khaled | 3                |\n| 2           | Ali    | 2                |\n| 3           | John   | 1                |\n| 4           | Doe    | 2                |\n+-------------+--------+------------------+\nOutput: \n+-------------+---------------+\n| project_id  | average_years |\n+-------------+---------------+\n| 1           | 2.00          |\n| 2           | 2.50          |\n+-------------+---------------+\nExplanation: The average experience years for the first project is (3 + 2 + 1) / 3 = 2.00 and for the second project is (3 + 2) / 2 = 2.50\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 444, + "dislikes": 112, + "isLiked": null, + "similarQuestions": "[{\"title\": \"Project Employees II\", \"titleSlug\": \"project-employees-ii\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]", + "exampleTestcases": "{\"headers\":{\"Project\":[\"project_id\",\"employee_id\"],\"Employee\":[\"employee_id\",\"name\",\"experience_years\"]},\"rows\":{\"Project\":[[1,1],[1,2],[1,3],[2,1],[2,4]],\"Employee\":[[1,\"Khaled\",3],[2,\"Ali\",2],[3,\"John\",1],[4,\"Doe\",2]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef project_employees_i(project: pd.DataFrame, employee: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"132.2K\", \"totalSubmission\": \"204.4K\", \"totalAcceptedRaw\": 132212, \"totalSubmissionRaw\": 204382, \"acRate\": \"64.7%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Project\":[\"project_id\",\"employee_id\"],\"Employee\":[\"employee_id\",\"name\",\"experience_years\"]},\"rows\":{\"Project\":[[1,1],[1,2],[1,3],[2,1],[2,4]],\"Employee\":[[1,\"Khaled\",3],[2,\"Ali\",2],[3,\"John\",1],[4,\"Doe\",2]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Project (project_id int, employee_id int)\", \"Create table If Not Exists Employee (employee_id int, name varchar(10), experience_years int)\"], \"mssql\": [\"Create table Project (project_id int, employee_id int)\", \"Create table Employee (employee_id int, name varchar(10), experience_years int)\"], \"oraclesql\": [\"Create table Project (project_id int, employee_id int)\", \"Create table Employee (employee_id int, name varchar(10), experience_years int)\"], \"database\": true, \"name\": \"project_employees_i\", \"pythondata\": [\"Project = pd.DataFrame([], columns=['project_id', 'employee_id']).astype({'project_id':'Int64', 'employee_id':'Int64'})\", \"Employee = pd.DataFrame([], columns=['employee_id', 'name', 'experience_years']).astype({'employee_id':'Int64', 'name':'object', 'experience_years':'Int64'})\"], \"postgresql\": [\"Create table If Not Exists Project (project_id int, employee_id int)\", \"Create table If Not Exists Employee (employee_id int, name varchar(10), experience_years int)\"], \"database_schema\": {\"Project\": {\"project_id\": \"INT\", \"employee_id\": \"INT\"}, \"Employee\": {\"employee_id\": \"INT\", \"name\": \"VARCHAR(10)\", \"experience_years\": \"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Project (project_id int, employee_id int)", + "Create table If Not Exists Employee (employee_id int, name varchar(10), experience_years int)", + "Truncate table Project", + "insert into Project (project_id, employee_id) values ('1', '1')", + "insert into Project (project_id, employee_id) values ('1', '2')", + "insert into Project (project_id, employee_id) values ('1', '3')", + "insert into Project (project_id, employee_id) values ('2', '1')", + "insert into Project (project_id, employee_id) values ('2', '4')", + "Truncate table Employee", + "insert into Employee (employee_id, name, experience_years) values ('1', 'Khaled', '3')", + "insert into Employee (employee_id, name, experience_years) values ('2', 'Ali', '2')", + "insert into Employee (employee_id, name, experience_years) values ('3', 'John', '1')", + "insert into Employee (employee_id, name, experience_years) values ('4', 'Doe', '2')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/queries-quality-and-percentage.json b/leetcode/originData/queries-quality-and-percentage.json new file mode 100644 index 00000000..84464b1a --- /dev/null +++ b/leetcode/originData/queries-quality-and-percentage.json @@ -0,0 +1,90 @@ +{ + "data": { + "question": { + "questionId": "1338", + "questionFrontendId": "1211", + "boundTopicId": null, + "title": "Queries Quality and Percentage", + "titleSlug": "queries-quality-and-percentage", + "content": "

Table: Queries

\n\n
\n+-------------+---------+\n| Column Name | Type    |\n+-------------+---------+\n| query_name  | varchar |\n| result      | varchar |\n| position    | int     |\n| rating      | int     |\n+-------------+---------+\nThis table may have duplicate rows.\nThis table contains information collected from some queries on a database.\nThe position column has a value from 1 to 500.\nThe rating column has a value from 1 to 5. Query with rating less than 3 is a poor query.\n
\n\n

 

\n\n

We define query quality as:

\n\n
\n

The average of the ratio between query rating and its position.

\n
\n\n

We also define poor query percentage as:

\n\n
\n

The percentage of all queries with rating less than 3.

\n
\n\n

Write a solution to find each query_name, the quality and poor_query_percentage.

\n\n

Both quality and poor_query_percentage should be rounded to 2 decimal places.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nQueries table:\n+------------+-------------------+----------+--------+\n| query_name | result            | position | rating |\n+------------+-------------------+----------+--------+\n| Dog        | Golden Retriever  | 1        | 5      |\n| Dog        | German Shepherd   | 2        | 5      |\n| Dog        | Mule              | 200      | 1      |\n| Cat        | Shirazi           | 5        | 2      |\n| Cat        | Siamese           | 3        | 3      |\n| Cat        | Sphynx            | 7        | 4      |\n+------------+-------------------+----------+--------+\nOutput: \n+------------+---------+-----------------------+\n| query_name | quality | poor_query_percentage |\n+------------+---------+-----------------------+\n| Dog        | 2.50    | 33.33                 |\n| Cat        | 0.66    | 33.33                 |\n+------------+---------+-----------------------+\nExplanation: \nDog queries quality is ((5 / 1) + (5 / 2) + (1 / 200)) / 3 = 2.50\nDog queries poor_ query_percentage is (1 / 3) * 100 = 33.33\n\nCat queries quality equals ((2 / 5) + (3 / 3) + (4 / 7)) / 3 = 0.66\nCat queries poor_ query_percentage is (1 / 3) * 100 = 33.33\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 456, + "dislikes": 322, + "isLiked": null, + "similarQuestions": "[{\"title\": \"Percentage of Users Attended a Contest\", \"titleSlug\": \"percentage-of-users-attended-a-contest\", \"difficulty\": \"Easy\", \"translatedTitle\": null}]", + "exampleTestcases": "{\"headers\":{\"Queries\":[\"query_name\",\"result\",\"position\",\"rating\"]},\"rows\":{\"Queries\":[[\"Dog\",\"Golden Retriever\",1,5],[\"Dog\",\"German Shepherd\",2,5],[\"Dog\",\"Mule\",200,1],[\"Cat\",\"Shirazi\",5,2],[\"Cat\",\"Siamese\",3,3],[\"Cat\",\"Sphynx\",7,4]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef queries_stats(queries: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"99.8K\", \"totalSubmission\": \"161.8K\", \"totalAcceptedRaw\": 99835, \"totalSubmissionRaw\": 161818, \"acRate\": \"61.7%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Queries\":[\"query_name\",\"result\",\"position\",\"rating\"]},\"rows\":{\"Queries\":[[\"Dog\",\"Golden Retriever\",1,5],[\"Dog\",\"German Shepherd\",2,5],[\"Dog\",\"Mule\",200,1],[\"Cat\",\"Shirazi\",5,2],[\"Cat\",\"Siamese\",3,3],[\"Cat\",\"Sphynx\",7,4]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Queries (query_name varchar(30), result varchar(50), position int, rating int)\"], \"mssql\": [\"create table Queries (query_name varchar(30), result varchar(50), position int, rating int)\"], \"oraclesql\": [\"create table Queries (query_name varchar(30), result varchar(50), position int, rating int)\"], \"database\": true, \"name\": \"queries_stats\", \"pythondata\": [\"Queries = pd.DataFrame([], columns=['query_name', 'result', 'position', 'rating']).astype({'query_name':'object', 'result':'object', 'position':'Int64', 'rating':'Int64'})\"], \"postgresql\": [\"\\nCreate table If Not Exists Queries (query_name varchar(30), result varchar(50), position int, rating int)\"], \"database_schema\": {\"Queries\": {\"query_name\": \"VARCHAR(30)\", \"result\": \"VARCHAR(50)\", \"position\": \"INT\", \"rating\": \"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Queries (query_name varchar(30), result varchar(50), position int, rating int)", + "Truncate table Queries", + "insert into Queries (query_name, result, position, rating) values ('Dog', 'Golden Retriever', '1', '5')", + "insert into Queries (query_name, result, position, rating) values ('Dog', 'German Shepherd', '2', '5')", + "insert into Queries (query_name, result, position, rating) values ('Dog', 'Mule', '200', '1')", + "insert into Queries (query_name, result, position, rating) values ('Cat', 'Shirazi', '5', '2')", + "insert into Queries (query_name, result, position, rating) values ('Cat', 'Siamese', '3', '3')", + "insert into Queries (query_name, result, position, rating) values ('Cat', 'Sphynx', '7', '4')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/replace-employee-id-with-the-unique-identifier.json b/leetcode/originData/replace-employee-id-with-the-unique-identifier.json new file mode 100644 index 00000000..4d457cd8 --- /dev/null +++ b/leetcode/originData/replace-employee-id-with-the-unique-identifier.json @@ -0,0 +1,101 @@ +{ + "data": { + "question": { + "questionId": "1509", + "questionFrontendId": "1378", + "boundTopicId": null, + "title": "Replace Employee ID With The Unique Identifier", + "titleSlug": "replace-employee-id-with-the-unique-identifier", + "content": "

Table: Employees

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| name          | varchar |\n+---------------+---------+\nid is the primary key (column with unique values) for this table.\nEach row of this table contains the id and the name of an employee in a company.\n
\n\n

 

\n\n

Table: EmployeeUNI

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| id            | int     |\n| unique_id     | int     |\n+---------------+---------+\n(id, unique_id) is the primary key (combination of columns with unique values) for this table.\nEach row of this table contains the id and the corresponding unique id of an employee in the company.\n
\n\n

 

\n\n

Write a solution to show the unique ID of each user, If a user does not have a unique ID replace just show null.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nEmployees table:\n+----+----------+\n| id | name     |\n+----+----------+\n| 1  | Alice    |\n| 7  | Bob      |\n| 11 | Meir     |\n| 90 | Winston  |\n| 3  | Jonathan |\n+----+----------+\nEmployeeUNI table:\n+----+-----------+\n| id | unique_id |\n+----+-----------+\n| 3  | 1         |\n| 11 | 2         |\n| 90 | 3         |\n+----+-----------+\nOutput: \n+-----------+----------+\n| unique_id | name     |\n+-----------+----------+\n| null      | Alice    |\n| null      | Bob      |\n| 2         | Meir     |\n| 3         | Winston  |\n| 1         | Jonathan |\n+-----------+----------+\nExplanation: \nAlice and Bob do not have a unique ID, We will show null instead.\nThe unique ID of Meir is 2.\nThe unique ID of Winston is 3.\nThe unique ID of Jonathan is 1.\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 827, + "dislikes": 85, + "isLiked": null, + "similarQuestions": "[]", + "exampleTestcases": "{\"headers\":{\"Employees\":[\"id\",\"name\"],\"EmployeeUNI\":[\"id\",\"unique_id\"]},\"rows\":{\"Employees\":[[1,\"Alice\"],[7,\"Bob\"],[11,\"Meir\"],[90,\"Winston\"],[3,\"Jonathan\"]],\"EmployeeUNI\":[[3,1],[11,2],[90,3]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef replace_employee_id(employees: pd.DataFrame, employee_uni: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"222.4K\", \"totalSubmission\": \"269.2K\", \"totalAcceptedRaw\": 222440, \"totalSubmissionRaw\": 269242, \"acRate\": \"82.6%\"}", + "hints": [], + "solution": { + "id": "2017", + "canSeeDetail": false, + "paidOnly": true, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "{\"headers\":{\"Employees\":[\"id\",\"name\"],\"EmployeeUNI\":[\"id\",\"unique_id\"]},\"rows\":{\"Employees\":[[1,\"Alice\"],[7,\"Bob\"],[11,\"Meir\"],[90,\"Winston\"],[3,\"Jonathan\"]],\"EmployeeUNI\":[[3,1],[11,2],[90,3]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Employees (id int, name varchar(20))\", \"Create table If Not Exists EmployeeUNI (id int, unique_id int)\"], \"mssql\": [\"Create table Employees (id int, name varchar(20))\", \"Create table EmployeeUNI (id int, unique_id int)\"], \"oraclesql\": [\"Create table Employees (id int, name varchar(20))\", \"Create table EmployeeUNI (id int, unique_id int)\"], \"database\": true, \"name\": \"replace_employee_id\", \"pythondata\": [\"Employees = pd.DataFrame([], columns=['id', 'name']).astype({'id':'int64', 'name':'object'})\", \"EmployeeUNI = pd.DataFrame([], columns=['id', 'unique_id']).astype({'id':'int64', 'unique_id':'int64'})\"], \"postgresql\": [\"\\nCreate table If Not Exists Employees (id int, name varchar(20))\\n\", \"Create table If Not Exists EmployeeUNI (id int, unique_id int)\"], \"database_schema\": {\"Employees\": {\"id\": \"INT\", \"name\": \"VARCHAR(20)\"}, \"EmployeeUNI\": {\"id\": \"INT\", \"unique_id\": \"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Employees (id int, name varchar(20))", + "Create table If Not Exists EmployeeUNI (id int, unique_id int)", + "Truncate table Employees", + "insert into Employees (id, name) values ('1', 'Alice')", + "insert into Employees (id, name) values ('7', 'Bob')", + "insert into Employees (id, name) values ('11', 'Meir')", + "insert into Employees (id, name) values ('90', 'Winston')", + "insert into Employees (id, name) values ('3', 'Jonathan')", + "Truncate table EmployeeUNI", + "insert into EmployeeUNI (id, unique_id) values ('3', '1')", + "insert into EmployeeUNI (id, unique_id) values ('11', '2')", + "insert into EmployeeUNI (id, unique_id) values ('90', '3')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/restaurant-growth.json b/leetcode/originData/restaurant-growth.json new file mode 100644 index 00000000..e53036f9 --- /dev/null +++ b/leetcode/originData/restaurant-growth.json @@ -0,0 +1,95 @@ +{ + "data": { + "question": { + "questionId": "1452", + "questionFrontendId": "1321", + "boundTopicId": null, + "title": "Restaurant Growth", + "titleSlug": "restaurant-growth", + "content": "

Table: Customer

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| customer_id   | int     |\n| name          | varchar |\n| visited_on    | date    |\n| amount        | int     |\n+---------------+---------+\nIn SQL,(customer_id, visited_on) is the primary key for this table.\nThis table contains data about customer transactions in a restaurant.\nvisited_on is the date on which the customer with ID (customer_id) has visited the restaurant.\namount is the total paid by a customer.\n
\n\n

 

\n\n

You are the restaurant owner and you want to analyze a possible expansion (there will be at least one customer every day).

\n\n

Compute the moving average of how much the customer paid in a seven days window (i.e., current day + 6 days before). average_amount should be rounded to two decimal places.

\n\n

Return the result table ordered by visited_on in ascending order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nCustomer table:\n+-------------+--------------+--------------+-------------+\n| customer_id | name         | visited_on   | amount      |\n+-------------+--------------+--------------+-------------+\n| 1           | Jhon         | 2019-01-01   | 100         |\n| 2           | Daniel       | 2019-01-02   | 110         |\n| 3           | Jade         | 2019-01-03   | 120         |\n| 4           | Khaled       | 2019-01-04   | 130         |\n| 5           | Winston      | 2019-01-05   | 110         | \n| 6           | Elvis        | 2019-01-06   | 140         | \n| 7           | Anna         | 2019-01-07   | 150         |\n| 8           | Maria        | 2019-01-08   | 80          |\n| 9           | Jaze         | 2019-01-09   | 110         | \n| 1           | Jhon         | 2019-01-10   | 130         | \n| 3           | Jade         | 2019-01-10   | 150         | \n+-------------+--------------+--------------+-------------+\nOutput: \n+--------------+--------------+----------------+\n| visited_on   | amount       | average_amount |\n+--------------+--------------+----------------+\n| 2019-01-07   | 860          | 122.86         |\n| 2019-01-08   | 840          | 120            |\n| 2019-01-09   | 840          | 120            |\n| 2019-01-10   | 1000         | 142.86         |\n+--------------+--------------+----------------+\nExplanation: \n1st moving average from 2019-01-01 to 2019-01-07 has an average_amount of (100 + 110 + 120 + 130 + 110 + 140 + 150)/7 = 122.86\n2nd moving average from 2019-01-02 to 2019-01-08 has an average_amount of (110 + 120 + 130 + 110 + 140 + 150 + 80)/7 = 120\n3rd moving average from 2019-01-03 to 2019-01-09 has an average_amount of (120 + 130 + 110 + 140 + 150 + 80 + 110)/7 = 120\n4th moving average from 2019-01-04 to 2019-01-10 has an average_amount of (130 + 110 + 140 + 150 + 80 + 110 + 130 + 150)/7 = 142.86\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Medium", + "likes": 629, + "dislikes": 225, + "isLiked": null, + "similarQuestions": "[]", + "exampleTestcases": "{\"headers\":{\"Customer\":[\"customer_id\",\"name\",\"visited_on\",\"amount\"]},\"rows\":{\"Customer\":[[1,\"Jhon\",\"2019-01-01\",100],[2,\"Daniel\",\"2019-01-02\",110],[3,\"Jade\",\"2019-01-03\",120],[4,\"Khaled\",\"2019-01-04\",130],[5,\"Winston\",\"2019-01-05\",110],[6,\"Elvis\",\"2019-01-06\",140],[7,\"Anna\",\"2019-01-07\",150],[8,\"Maria\",\"2019-01-08\",80],[9,\"Jaze\",\"2019-01-09\",110],[1,\"Jhon\",\"2019-01-10\",130],[3,\"Jade\",\"2019-01-10\",150]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef restaurant_growth(customer: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"54.9K\", \"totalSubmission\": \"114.2K\", \"totalAcceptedRaw\": 54858, \"totalSubmissionRaw\": 114223, \"acRate\": \"48.0%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Customer\":[\"customer_id\",\"name\",\"visited_on\",\"amount\"]},\"rows\":{\"Customer\":[[1,\"Jhon\",\"2019-01-01\",100],[2,\"Daniel\",\"2019-01-02\",110],[3,\"Jade\",\"2019-01-03\",120],[4,\"Khaled\",\"2019-01-04\",130],[5,\"Winston\",\"2019-01-05\",110],[6,\"Elvis\",\"2019-01-06\",140],[7,\"Anna\",\"2019-01-07\",150],[8,\"Maria\",\"2019-01-08\",80],[9,\"Jaze\",\"2019-01-09\",110],[1,\"Jhon\",\"2019-01-10\",130],[3,\"Jade\",\"2019-01-10\",150]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Customer (customer_id int, name varchar(20), visited_on date, amount int)\"], \"mssql\": [\"Create table Customer (customer_id int, name varchar(20), visited_on date, amount int)\"], \"oraclesql\": [\"Create table Customer (customer_id int, name varchar(20), visited_on date, amount int)\", \"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"], \"database\": true, \"name\": \"restaurant_growth\", \"pythondata\": [\"Customer = pd.DataFrame([], columns=['customer_id', 'name', 'visited_on', 'amount']).astype({'customer_id':'Int64', 'name':'object', 'visited_on':'datetime64[ns]', 'amount':'Int64'})\"], \"postgresql\": [\"\\nCreate table If Not Exists Customer (customer_id int, name varchar(20), visited_on date, amount int)\"], \"database_schema\": {\"Customer\": {\"customer_id\": \"INT\", \"name\": \"VARCHAR(20)\", \"visited_on\": \"DATE\", \"amount\": \"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Customer (customer_id int, name varchar(20), visited_on date, amount int)", + "Truncate table Customer", + "insert into Customer (customer_id, name, visited_on, amount) values ('1', 'Jhon', '2019-01-01', '100')", + "insert into Customer (customer_id, name, visited_on, amount) values ('2', 'Daniel', '2019-01-02', '110')", + "insert into Customer (customer_id, name, visited_on, amount) values ('3', 'Jade', '2019-01-03', '120')", + "insert into Customer (customer_id, name, visited_on, amount) values ('4', 'Khaled', '2019-01-04', '130')", + "insert into Customer (customer_id, name, visited_on, amount) values ('5', 'Winston', '2019-01-05', '110')", + "insert into Customer (customer_id, name, visited_on, amount) values ('6', 'Elvis', '2019-01-06', '140')", + "insert into Customer (customer_id, name, visited_on, amount) values ('7', 'Anna', '2019-01-07', '150')", + "insert into Customer (customer_id, name, visited_on, amount) values ('8', 'Maria', '2019-01-08', '80')", + "insert into Customer (customer_id, name, visited_on, amount) values ('9', 'Jaze', '2019-01-09', '110')", + "insert into Customer (customer_id, name, visited_on, amount) values ('1', 'Jhon', '2019-01-10', '130')", + "insert into Customer (customer_id, name, visited_on, amount) values ('3', 'Jade', '2019-01-10', '150')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/students-and-examinations.json b/leetcode/originData/students-and-examinations.json new file mode 100644 index 00000000..edee6b65 --- /dev/null +++ b/leetcode/originData/students-and-examinations.json @@ -0,0 +1,113 @@ +{ + "data": { + "question": { + "questionId": "1415", + "questionFrontendId": "1280", + "boundTopicId": null, + "title": "Students and Examinations", + "titleSlug": "students-and-examinations", + "content": "

Table: Students

\n\n
\n+---------------+---------+\n| Column Name   | Type    |\n+---------------+---------+\n| student_id    | int     |\n| student_name  | varchar |\n+---------------+---------+\nstudent_id is the primary key (column with unique values) for this table.\nEach row of this table contains the ID and the name of one student in the school.\n
\n\n

 

\n\n

Table: Subjects

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| subject_name | varchar |\n+--------------+---------+\nsubject_name is the primary key (column with unique values) for this table.\nEach row of this table contains the name of one subject in the school.\n
\n\n

 

\n\n

Table: Examinations

\n\n
\n+--------------+---------+\n| Column Name  | Type    |\n+--------------+---------+\n| student_id   | int     |\n| subject_name | varchar |\n+--------------+---------+\nThere is no primary key (column with unique values) for this table. It may contain duplicates.\nEach student from the Students table takes every course from the Subjects table.\nEach row of this table indicates that a student with ID student_id attended the exam of subject_name.\n
\n\n

 

\n\n

Write a solution to find the number of times each student attended each exam.

\n\n

Return the result table ordered by student_id and subject_name.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nStudents table:\n+------------+--------------+\n| student_id | student_name |\n+------------+--------------+\n| 1          | Alice        |\n| 2          | Bob          |\n| 13         | John         |\n| 6          | Alex         |\n+------------+--------------+\nSubjects table:\n+--------------+\n| subject_name |\n+--------------+\n| Math         |\n| Physics      |\n| Programming  |\n+--------------+\nExaminations table:\n+------------+--------------+\n| student_id | subject_name |\n+------------+--------------+\n| 1          | Math         |\n| 1          | Physics      |\n| 1          | Programming  |\n| 2          | Programming  |\n| 1          | Physics      |\n| 1          | Math         |\n| 13         | Math         |\n| 13         | Programming  |\n| 13         | Physics      |\n| 2          | Math         |\n| 1          | Math         |\n+------------+--------------+\nOutput: \n+------------+--------------+--------------+----------------+\n| student_id | student_name | subject_name | attended_exams |\n+------------+--------------+--------------+----------------+\n| 1          | Alice        | Math         | 3              |\n| 1          | Alice        | Physics      | 2              |\n| 1          | Alice        | Programming  | 1              |\n| 2          | Bob          | Math         | 1              |\n| 2          | Bob          | Physics      | 0              |\n| 2          | Bob          | Programming  | 1              |\n| 6          | Alex         | Math         | 0              |\n| 6          | Alex         | Physics      | 0              |\n| 6          | Alex         | Programming  | 0              |\n| 13         | John         | Math         | 1              |\n| 13         | John         | Physics      | 1              |\n| 13         | John         | Programming  | 1              |\n+------------+--------------+--------------+----------------+\nExplanation: \nThe result table should contain all students and all subjects.\nAlice attended the Math exam 3 times, the Physics exam 2 times, and the Programming exam 1 time.\nBob attended the Math exam 1 time, the Programming exam 1 time, and did not attend the Physics exam.\nAlex did not attend any exams.\nJohn attended the Math exam 1 time, the Physics exam 1 time, and the Programming exam 1 time.\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 1236, + "dislikes": 160, + "isLiked": null, + "similarQuestions": "[]", + "exampleTestcases": "{\"headers\":{\"Students\":[\"student_id\",\"student_name\"],\"Subjects\":[\"subject_name\"],\"Examinations\":[\"student_id\",\"subject_name\"]},\"rows\":{\"Students\":[[1,\"Alice\"],[2,\"Bob\"],[13,\"John\"],[6,\"Alex\"]],\"Subjects\":[[\"Math\"],[\"Physics\"],[\"Programming\"]],\"Examinations\":[[1,\"Math\"],[1,\"Physics\"],[1,\"Programming\"],[2,\"Programming\"],[1,\"Physics\"],[1,\"Math\"],[13,\"Math\"],[13,\"Programming\"],[13,\"Physics\"],[2,\"Math\"],[1,\"Math\"]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef students_and_examinations(students: pd.DataFrame, subjects: pd.DataFrame, examinations: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"129.8K\", \"totalSubmission\": \"230.8K\", \"totalAcceptedRaw\": 129823, \"totalSubmissionRaw\": 230750, \"acRate\": \"56.3%\"}", + "hints": [], + "solution": { + "id": "2018", + "canSeeDetail": false, + "paidOnly": true, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "{\"headers\":{\"Students\":[\"student_id\",\"student_name\"],\"Subjects\":[\"subject_name\"],\"Examinations\":[\"student_id\",\"subject_name\"]},\"rows\":{\"Students\":[[1,\"Alice\"],[2,\"Bob\"],[13,\"John\"],[6,\"Alex\"]],\"Subjects\":[[\"Math\"],[\"Physics\"],[\"Programming\"]],\"Examinations\":[[1,\"Math\"],[1,\"Physics\"],[1,\"Programming\"],[2,\"Programming\"],[1,\"Physics\"],[1,\"Math\"],[13,\"Math\"],[13,\"Programming\"],[13,\"Physics\"],[2,\"Math\"],[1,\"Math\"]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Students (student_id int, student_name varchar(20))\", \"Create table If Not Exists Subjects (subject_name varchar(20))\", \"Create table If Not Exists Examinations (student_id int, subject_name varchar(20))\"], \"mssql\": [\"Create table Students (student_id int, student_name varchar(20))\", \"Create table Subjects (subject_name varchar(20))\", \"Create table Examinations (student_id int, subject_name varchar(20))\"], \"oraclesql\": [\"Create table Students (student_id int, student_name varchar(20))\\n\", \"Create table Subjects (subject_name varchar(20))\\n\", \"Create table Examinations (student_id int, subject_name varchar(20))\"], \"database\": true, \"name\": \"students_and_examinations\", \"pythondata\": [\"Students = pd.DataFrame([], columns=['student_id', 'student_name']).astype({'student_id':'Int64', 'student_name':'object'})\", \"Subjects = pd.DataFrame([], columns=['subject_name']).astype({'subject_name':'object'})\", \"Examinations = pd.DataFrame([], columns=['student_id', 'subject_name']).astype({'student_id':'Int64', 'subject_name':'object'})\"], \"manual\": false, \"postgresql\": [\"\\nCreate table If Not Exists Students (student_id int, student_name varchar(20))\\n\", \"Create table If Not Exists Subjects (subject_name varchar(20))\", \"Create table If Not Exists Examinations (student_id int, subject_name varchar(20))\"], \"database_schema\": {\"Students\": {\"student_id\": \"INT\", \"student_name\": \"VARCHAR(20)\"}, \"Subjects\": {\"subject_name\": \"VARCHAR(20)\"}, \"Examinations\": {\"student_id\": \"INT\", \"subject_name\": \"VARCHAR(20)\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Students (student_id int, student_name varchar(20))", + "Create table If Not Exists Subjects (subject_name varchar(20))", + "Create table If Not Exists Examinations (student_id int, subject_name varchar(20))", + "Truncate table Students", + "insert into Students (student_id, student_name) values ('1', 'Alice')", + "insert into Students (student_id, student_name) values ('2', 'Bob')", + "insert into Students (student_id, student_name) values ('13', 'John')", + "insert into Students (student_id, student_name) values ('6', 'Alex')", + "Truncate table Subjects", + "insert into Subjects (subject_name) values ('Math')", + "insert into Subjects (subject_name) values ('Physics')", + "insert into Subjects (subject_name) values ('Programming')", + "Truncate table Examinations", + "insert into Examinations (student_id, subject_name) values ('1', 'Math')", + "insert into Examinations (student_id, subject_name) values ('1', 'Physics')", + "insert into Examinations (student_id, subject_name) values ('1', 'Programming')", + "insert into Examinations (student_id, subject_name) values ('2', 'Programming')", + "insert into Examinations (student_id, subject_name) values ('1', 'Physics')", + "insert into Examinations (student_id, subject_name) values ('1', 'Math')", + "insert into Examinations (student_id, subject_name) values ('13', 'Math')", + "insert into Examinations (student_id, subject_name) values ('13', 'Programming')", + "insert into Examinations (student_id, subject_name) values ('13', 'Physics')", + "insert into Examinations (student_id, subject_name) values ('2', 'Math')", + "insert into Examinations (student_id, subject_name) values ('1', 'Math')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/the-number-of-employees-which-report-to-each-employee.json b/leetcode/originData/the-number-of-employees-which-report-to-each-employee.json new file mode 100644 index 00000000..a9f5586d --- /dev/null +++ b/leetcode/originData/the-number-of-employees-which-report-to-each-employee.json @@ -0,0 +1,88 @@ +{ + "data": { + "question": { + "questionId": "1882", + "questionFrontendId": "1731", + "boundTopicId": null, + "title": "The Number of Employees Which Report to Each Employee", + "titleSlug": "the-number-of-employees-which-report-to-each-employee", + "content": "

Table: Employees

\n\n
\n+-------------+----------+\n| Column Name | Type     |\n+-------------+----------+\n| employee_id | int      |\n| name        | varchar  |\n| reports_to  | int      |\n| age         | int      |\n+-------------+----------+\nemployee_id is the column with unique values for this table.\nThis table contains information about the employees and the id of the manager they report to. Some employees do not report to anyone (reports_to is null). \n
\n\n

 

\n\n

For this problem, we will consider a manager an employee who has at least 1 other employee reporting to them.

\n\n

Write a solution to report the ids and the names of all managers, the number of employees who report directly to them, and the average age of the reports rounded to the nearest integer.

\n\n

Return the result table ordered by employee_id.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nEmployees table:\n+-------------+---------+------------+-----+\n| employee_id | name    | reports_to | age |\n+-------------+---------+------------+-----+\n| 9           | Hercy   | null       | 43  |\n| 6           | Alice   | 9          | 41  |\n| 4           | Bob     | 9          | 36  |\n| 2           | Winston | null       | 37  |\n+-------------+---------+------------+-----+\nOutput: \n+-------------+-------+---------------+-------------+\n| employee_id | name  | reports_count | average_age |\n+-------------+-------+---------------+-------------+\n| 9           | Hercy | 2             | 39          |\n+-------------+-------+---------------+-------------+\nExplanation: Hercy has 2 people report directly to him, Alice and Bob. Their average age is (41+36)/2 = 38.5, which is 39 after rounding it to the nearest integer.\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 374, + "dislikes": 52, + "isLiked": null, + "similarQuestions": "[]", + "exampleTestcases": "{\"headers\":{\"Employees\":[\"employee_id\",\"name\",\"reports_to\",\"age\"]},\"rows\":{\"Employees\":[[9,\"Hercy\",null,43],[6,\"Alice\",9,41],[4,\"Bob\",9,36],[2,\"Winston\",null,37]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef count_employees(employees: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"65K\", \"totalSubmission\": \"145.1K\", \"totalAcceptedRaw\": 65040, \"totalSubmissionRaw\": 145130, \"acRate\": \"44.8%\"}", + "hints": [], + "solution": null, + "status": null, + "sampleTestCase": "{\"headers\":{\"Employees\":[\"employee_id\",\"name\",\"reports_to\",\"age\"]},\"rows\":{\"Employees\":[[9,\"Hercy\",null,43],[6,\"Alice\",9,41],[4,\"Bob\",9,36],[2,\"Winston\",null,37]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Employees(employee_id int, name varchar(20), reports_to int, age int)\"], \"mssql\": [\"Create table Employees(employee_id int, name varchar(20), reports_to int, age int)\"], \"oraclesql\": [\"Create table Employees(employee_id int, name varchar(20), reports_to int, age int)\"], \"database\": true, \"name\": \"count_employees\", \"pythondata\": [\"Employees = pd.DataFrame([], columns=['employee_id', 'name', 'reports_to', 'age']).astype({'employee_id':'Int64', 'name':'object', 'reports_to':'Int64', 'age':'Int64'})\"], \"postgresql\": [\"Create table If Not Exists Employees(employee_id int, name varchar(20), reports_to int, age int)\"], \"database_schema\": {\"Employees\": {\"employee_id\": \"INT\", \"name\": \"VARCHAR(20)\", \"reports_to\": \"INT\", \"age\": \"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Employees(employee_id int, name varchar(20), reports_to int, age int)", + "Truncate table Employees", + "insert into Employees (employee_id, name, reports_to, age) values ('9', 'Hercy', 'None', '43')", + "insert into Employees (employee_id, name, reports_to, age) values ('6', 'Alice', '9', '41')", + "insert into Employees (employee_id, name, reports_to, age) values ('4', 'Bob', '9', '36')", + "insert into Employees (employee_id, name, reports_to, age) values ('2', 'Winston', 'None', '37')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/originData/triangle-judgement.json b/leetcode/originData/triangle-judgement.json new file mode 100644 index 00000000..bae2d5f3 --- /dev/null +++ b/leetcode/originData/triangle-judgement.json @@ -0,0 +1,93 @@ +{ + "data": { + "question": { + "questionId": "610", + "questionFrontendId": "610", + "boundTopicId": null, + "title": "Triangle Judgement", + "titleSlug": "triangle-judgement", + "content": "

Table: Triangle

\n\n
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| x           | int  |\n| y           | int  |\n| z           | int  |\n+-------------+------+\nIn SQL, (x, y, z) is the primary key column for this table.\nEach row of this table contains the lengths of three line segments.\n
\n\n

 

\n\n

Report for every three line segments whether they can form a triangle.

\n\n

Return the result table in any order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example 1:

\n\n
\nInput: \nTriangle table:\n+----+----+----+\n| x  | y  | z  |\n+----+----+----+\n| 13 | 15 | 30 |\n| 10 | 20 | 15 |\n+----+----+----+\nOutput: \n+----+----+----+----------+\n| x  | y  | z  | triangle |\n+----+----+----+----------+\n| 13 | 15 | 30 | No       |\n| 10 | 20 | 15 | Yes      |\n+----+----+----+----------+\n
\n", + "translatedTitle": null, + "translatedContent": null, + "isPaidOnly": false, + "difficulty": "Easy", + "likes": 497, + "dislikes": 129, + "isLiked": null, + "similarQuestions": "[]", + "exampleTestcases": "{\"headers\":{\"Triangle\":[\"x\",\"y\",\"z\"]},\"rows\":{\"Triangle\":[[13,15,30],[10,20,15]]}}", + "categoryTitle": "Database", + "contributors": [], + "topicTags": [ + { + "name": "Database", + "slug": "database", + "translatedName": null, + "__typename": "TopicTagNode" + } + ], + "companyTagStats": null, + "codeSnippets": [ + { + "lang": "MySQL", + "langSlug": "mysql", + "code": "# Write your MySQL query statement below\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "MS SQL Server", + "langSlug": "mssql", + "code": "/* Write your T-SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Oracle", + "langSlug": "oraclesql", + "code": "/* Write your PL/SQL query statement below */\n", + "__typename": "CodeSnippetNode" + }, + { + "lang": "Pandas", + "langSlug": "pythondata", + "code": "import pandas as pd\n\ndef triangle_judgement(triangle: pd.DataFrame) -> pd.DataFrame:\n ", + "__typename": "CodeSnippetNode" + }, + { + "lang": "PostgreSQL", + "langSlug": "postgresql", + "code": "-- Write your PostgreSQL query statement below\n", + "__typename": "CodeSnippetNode" + } + ], + "stats": "{\"totalAccepted\": \"119.6K\", \"totalSubmission\": \"169.5K\", \"totalAcceptedRaw\": 119604, \"totalSubmissionRaw\": 169454, \"acRate\": \"70.6%\"}", + "hints": [], + "solution": { + "id": "180", + "canSeeDetail": false, + "paidOnly": true, + "hasVideoSolution": false, + "paidOnlyVideo": true, + "__typename": "ArticleNode" + }, + "status": null, + "sampleTestCase": "{\"headers\":{\"Triangle\":[\"x\",\"y\",\"z\"]},\"rows\":{\"Triangle\":[[13,15,30],[10,20,15]]}}", + "metaData": "{\"mysql\": [\"Create table If Not Exists Triangle (x int, y int, z int)\"], \"mssql\": [\"Create table Triangle (x int, y int, z int)\"], \"oraclesql\": [\"Create table Triangle (x int, y int, z int)\"], \"database\": true, \"name\": \"triangle_judgement\", \"pythondata\": [\"Triangle = pd.DataFrame([], columns=['x', 'y', 'z']).astype({'x':'Int64', 'y':'Int64', 'z':'Int64'})\"], \"postgresql\": [\"Create table If Not Exists Triangle (x int, y int, z int)\"], \"database_schema\": {\"Triangle\": {\"x\": \"INT\", \"y\": \"INT\", \"z\": \"INT\"}}}", + "judgerAvailable": true, + "judgeType": "large", + "mysqlSchemas": [ + "Create table If Not Exists Triangle (x int, y int, z int)", + "Truncate table Triangle", + "insert into Triangle (x, y, z) values ('13', '15', '30')", + "insert into Triangle (x, y, z) values ('10', '20', '15')" + ], + "enableRunCode": true, + "enableTestMode": false, + "enableDebugger": false, + "envInfo": "{\"mysql\": [\"MySQL\", \"

MySQL 8.0.

\"], \"mssql\": [\"MS SQL Server\", \"

mssql server 2019.

\"], \"oraclesql\": [\"Oracle\", \"

Oracle Sql 11.2.

\"], \"pythondata\": [\"Pandas\", \"

Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0

\"], \"postgresql\": [\"PostgreSQL\", \"

PostgreSQL 16

\"]}", + "libraryUrl": null, + "adminUrl": null, + "challengeQuestion": null, + "__typename": "QuestionNode" + } + } +} \ No newline at end of file diff --git a/leetcode/problem/average-selling-price.html b/leetcode/problem/average-selling-price.html new file mode 100644 index 00000000..57b8d9b5 --- /dev/null +++ b/leetcode/problem/average-selling-price.html @@ -0,0 +1,75 @@ +

Table: Prices

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| product_id    | int     |
+| start_date    | date    |
+| end_date      | date    |
+| price         | int     |
++---------------+---------+
+(product_id, start_date, end_date) is the primary key (combination of columns with unique values) for this table.
+Each row of this table indicates the price of the product_id in the period from start_date to end_date.
+For each product_id there will be no two overlapping periods. That means there will be no two intersecting periods for the same product_id.
+
+ +

 

+ +

Table: UnitsSold

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| product_id    | int     |
+| purchase_date | date    |
+| units         | int     |
++---------------+---------+
+This table may contain duplicate rows.
+Each row of this table indicates the date, units, and product_id of each product sold. 
+
+ +

 

+ +

Write a solution to find the average selling price for each product. average_price should be rounded to 2 decimal places.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Prices table:
++------------+------------+------------+--------+
+| product_id | start_date | end_date   | price  |
++------------+------------+------------+--------+
+| 1          | 2019-02-17 | 2019-02-28 | 5      |
+| 1          | 2019-03-01 | 2019-03-22 | 20     |
+| 2          | 2019-02-01 | 2019-02-20 | 15     |
+| 2          | 2019-02-21 | 2019-03-31 | 30     |
++------------+------------+------------+--------+
+UnitsSold table:
++------------+---------------+-------+
+| product_id | purchase_date | units |
++------------+---------------+-------+
+| 1          | 2019-02-25    | 100   |
+| 1          | 2019-03-01    | 15    |
+| 2          | 2019-02-10    | 200   |
+| 2          | 2019-03-22    | 30    |
++------------+---------------+-------+
+Output: 
++------------+---------------+
+| product_id | average_price |
++------------+---------------+
+| 1          | 6.96          |
+| 2          | 16.96         |
++------------+---------------+
+Explanation: 
+Average selling price = Total Price of Product / Number of products sold.
+Average selling price for product 1 = ((100 * 5) + (15 * 20)) / 115 = 6.96
+Average selling price for product 2 = ((200 * 15) + (30 * 30)) / 230 = 16.96
+
diff --git a/leetcode/problem/average-time-of-process-per-machine.html b/leetcode/problem/average-time-of-process-per-machine.html new file mode 100644 index 00000000..cabce950 --- /dev/null +++ b/leetcode/problem/average-time-of-process-per-machine.html @@ -0,0 +1,68 @@ +

Table: Activity

+ +
++----------------+---------+
+| Column Name    | Type    |
++----------------+---------+
+| machine_id     | int     |
+| process_id     | int     |
+| activity_type  | enum    |
+| timestamp      | float   |
++----------------+---------+
+The table shows the user activities for a factory website.
+(machine_id, process_id, activity_type) is the primary key (combination of columns with unique values) of this table.
+machine_id is the ID of a machine.
+process_id is the ID of a process running on the machine with ID machine_id.
+activity_type is an ENUM (category) of type ('start', 'end').
+timestamp is a float representing the current time in seconds.
+'start' means the machine starts the process at the given timestamp and 'end' means the machine ends the process at the given timestamp.
+The 'start' timestamp will always be before the 'end' timestamp for every (machine_id, process_id) pair.
+ +

 

+ +

There is a factory website that has several machines each running the same number of processes. Write a solution to find the average time each machine takes to complete a process.

+ +

The time to complete a process is the 'end' timestamp minus the 'start' timestamp. The average time is calculated by the total time to complete every process on the machine divided by the number of processes that were run.

+ +

The resulting table should have the machine_id along with the average time as processing_time, which should be rounded to 3 decimal places.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Activity table:
++------------+------------+---------------+-----------+
+| machine_id | process_id | activity_type | timestamp |
++------------+------------+---------------+-----------+
+| 0          | 0          | start         | 0.712     |
+| 0          | 0          | end           | 1.520     |
+| 0          | 1          | start         | 3.140     |
+| 0          | 1          | end           | 4.120     |
+| 1          | 0          | start         | 0.550     |
+| 1          | 0          | end           | 1.550     |
+| 1          | 1          | start         | 0.430     |
+| 1          | 1          | end           | 1.420     |
+| 2          | 0          | start         | 4.100     |
+| 2          | 0          | end           | 4.512     |
+| 2          | 1          | start         | 2.500     |
+| 2          | 1          | end           | 5.000     |
++------------+------------+---------------+-----------+
+Output: 
++------------+-----------------+
+| machine_id | processing_time |
++------------+-----------------+
+| 0          | 0.894           |
+| 1          | 0.995           |
+| 2          | 1.456           |
++------------+-----------------+
+Explanation: 
+There are 3 machines running 2 processes each.
+Machine 0's average time is ((1.520 - 0.712) + (4.120 - 3.140)) / 2 = 0.894
+Machine 1's average time is ((1.550 - 0.550) + (1.420 - 0.430)) / 2 = 0.995
+Machine 2's average time is ((4.512 - 4.100) + (5.000 - 2.500)) / 2 = 1.456
+
diff --git a/leetcode/problem/biggest-single-number.html b/leetcode/problem/biggest-single-number.html new file mode 100644 index 00000000..b99439e1 --- /dev/null +++ b/leetcode/problem/biggest-single-number.html @@ -0,0 +1,72 @@ +

Table: MyNumbers

+ +
++-------------+------+
+| Column Name | Type |
++-------------+------+
+| num         | int  |
++-------------+------+
+This table may contain duplicates (In other words, there is no primary key for this table in SQL).
+Each row of this table contains an integer.
+
+ +

 

+ +

A single number is a number that appeared only once in the MyNumbers table.

+ +

Find the largest single number. If there is no single number, report null.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+MyNumbers table:
++-----+
+| num |
++-----+
+| 8   |
+| 8   |
+| 3   |
+| 3   |
+| 1   |
+| 4   |
+| 5   |
+| 6   |
++-----+
+Output: 
++-----+
+| num |
++-----+
+| 6   |
++-----+
+Explanation: The single numbers are 1, 4, 5, and 6.
+Since 6 is the largest single number, we return it.
+
+ +

Example 2:

+ +
+Input: 
+MyNumbers table:
++-----+
+| num |
++-----+
+| 8   |
+| 8   |
+| 7   |
+| 7   |
+| 3   |
+| 3   |
+| 3   |
++-----+
+Output: 
++------+
+| num  |
++------+
+| null |
++------+
+Explanation: There are no single numbers in the input table so we return null.
+
diff --git a/leetcode/problem/confirmation-rate.html b/leetcode/problem/confirmation-rate.html new file mode 100644 index 00000000..d528355b --- /dev/null +++ b/leetcode/problem/confirmation-rate.html @@ -0,0 +1,82 @@ +

Table: Signups

+ +
++----------------+----------+
+| Column Name    | Type     |
++----------------+----------+
+| user_id        | int      |
+| time_stamp     | datetime |
++----------------+----------+
+user_id is the column of unique values for this table.
+Each row contains information about the signup time for the user with ID user_id.
+
+ +

 

+ +

Table: Confirmations

+ +
++----------------+----------+
+| Column Name    | Type     |
++----------------+----------+
+| user_id        | int      |
+| time_stamp     | datetime |
+| action         | ENUM     |
++----------------+----------+
+(user_id, time_stamp) is the primary key (combination of columns with unique values) for this table.
+user_id is a foreign key (reference column) to the Signups table.
+action is an ENUM (category) of the type ('confirmed', 'timeout')
+Each row of this table indicates that the user with ID user_id requested a confirmation message at time_stamp and that confirmation message was either confirmed ('confirmed') or expired without confirming ('timeout').
+
+ +

 

+ +

The confirmation rate of a user is the number of 'confirmed' messages divided by the total number of requested confirmation messages. The confirmation rate of a user that did not request any confirmation messages is 0. Round the confirmation rate to two decimal places.

+ +

Write a solution to find the confirmation rate of each user.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Signups table:
++---------+---------------------+
+| user_id | time_stamp          |
++---------+---------------------+
+| 3       | 2020-03-21 10:16:13 |
+| 7       | 2020-01-04 13:57:59 |
+| 2       | 2020-07-29 23:09:44 |
+| 6       | 2020-12-09 10:39:37 |
++---------+---------------------+
+Confirmations table:
++---------+---------------------+-----------+
+| user_id | time_stamp          | action    |
++---------+---------------------+-----------+
+| 3       | 2021-01-06 03:30:46 | timeout   |
+| 3       | 2021-07-14 14:00:00 | timeout   |
+| 7       | 2021-06-12 11:57:29 | confirmed |
+| 7       | 2021-06-13 12:58:28 | confirmed |
+| 7       | 2021-06-14 13:59:27 | confirmed |
+| 2       | 2021-01-22 00:00:00 | confirmed |
+| 2       | 2021-02-28 23:59:59 | timeout   |
++---------+---------------------+-----------+
+Output: 
++---------+-------------------+
+| user_id | confirmation_rate |
++---------+-------------------+
+| 6       | 0.00              |
+| 3       | 0.00              |
+| 7       | 1.00              |
+| 2       | 0.50              |
++---------+-------------------+
+Explanation: 
+User 6 did not request any confirmation messages. The confirmation rate is 0.
+User 3 made 2 requests and both timed out. The confirmation rate is 0.
+User 7 made 3 requests and all were confirmed. The confirmation rate is 1.
+User 2 made 2 requests where one was confirmed and the other timed out. The confirmation rate is 1 / 2 = 0.5.
+
diff --git a/leetcode/problem/count-salary-categories.html b/leetcode/problem/count-salary-categories.html new file mode 100644 index 00000000..1dd314d2 --- /dev/null +++ b/leetcode/problem/count-salary-categories.html @@ -0,0 +1,56 @@ +

Table: Accounts

+ +
++-------------+------+
+| Column Name | Type |
++-------------+------+
+| account_id  | int  |
+| income      | int  |
++-------------+------+
+account_id is the primary key (column with unique values) for this table.
+Each row contains information about the monthly income for one bank account.
+
+ +

 

+ +

Write a solution to calculate the number of bank accounts for each salary category. The salary categories are:

+ +
    +
  • "Low Salary": All the salaries strictly less than $20000.
  • +
  • "Average Salary": All the salaries in the inclusive range [$20000, $50000].
  • +
  • "High Salary": All the salaries strictly greater than $50000.
  • +
+ +

The result table must contain all three categories. If there are no accounts in a category, return 0.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Accounts table:
++------------+--------+
+| account_id | income |
++------------+--------+
+| 3          | 108939 |
+| 2          | 12747  |
+| 8          | 87709  |
+| 6          | 91796  |
++------------+--------+
+Output: 
++----------------+----------------+
+| category       | accounts_count |
++----------------+----------------+
+| Low Salary     | 1              |
+| Average Salary | 0              |
+| High Salary    | 3              |
++----------------+----------------+
+Explanation: 
+Low Salary: Account 2.
+Average Salary: No accounts.
+High Salary: Accounts 3, 6, and 8.
+
diff --git a/leetcode/problem/customers-who-bought-all-products.html b/leetcode/problem/customers-who-bought-all-products.html new file mode 100644 index 00000000..867e330d --- /dev/null +++ b/leetcode/problem/customers-who-bought-all-products.html @@ -0,0 +1,67 @@ +

Table: Customer

+ +
++-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| customer_id | int     |
+| product_key | int     |
++-------------+---------+
+This table may contain duplicates rows. 
+customer_id is not NULL.
+product_key is a foreign key (reference column) to Product table.
+
+ +

 

+ +

Table: Product

+ +
++-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| product_key | int     |
++-------------+---------+
+product_key is the primary key (column with unique values) for this table.
+
+ +

 

+ +

Write a solution to report the customer ids from the Customer table that bought all the products in the Product table.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Customer table:
++-------------+-------------+
+| customer_id | product_key |
++-------------+-------------+
+| 1           | 5           |
+| 2           | 6           |
+| 3           | 5           |
+| 3           | 6           |
+| 1           | 6           |
++-------------+-------------+
+Product table:
++-------------+
+| product_key |
++-------------+
+| 5           |
+| 6           |
++-------------+
+Output: 
++-------------+
+| customer_id |
++-------------+
+| 1           |
+| 3           |
++-------------+
+Explanation: 
+The customers who bought all the products (5 and 6) are customers with IDs 1 and 3.
+
diff --git a/leetcode/problem/employee-bonus.html b/leetcode/problem/employee-bonus.html new file mode 100644 index 00000000..5e370b53 --- /dev/null +++ b/leetcode/problem/employee-bonus.html @@ -0,0 +1,69 @@ +

Table: Employee

+ +
++-------------+---------+
+| Column Name | Type    |
++-------------+---------+
+| empId       | int     |
+| name        | varchar |
+| supervisor  | int     |
+| salary      | int     |
++-------------+---------+
+empId is the column with unique values for this table.
+Each row of this table indicates the name and the ID of an employee in addition to their salary and the id of their manager.
+
+ +

 

+ +

Table: Bonus

+ +
++-------------+------+
+| Column Name | Type |
++-------------+------+
+| empId       | int  |
+| bonus       | int  |
++-------------+------+
+empId is the column of unique values for this table.
+empId is a foreign key (reference column) to empId from the Employee table.
+Each row of this table contains the id of an employee and their respective bonus.
+
+ +

 

+ +

Write a solution to report the name and bonus amount of each employee with a bonus less than 1000.

+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Employee table:
++-------+--------+------------+--------+
+| empId | name   | supervisor | salary |
++-------+--------+------------+--------+
+| 3     | Brad   | null       | 4000   |
+| 1     | John   | 3          | 1000   |
+| 2     | Dan    | 3          | 2000   |
+| 4     | Thomas | 3          | 4000   |
++-------+--------+------------+--------+
+Bonus table:
++-------+-------+
+| empId | bonus |
++-------+-------+
+| 2     | 500   |
+| 4     | 2000  |
++-------+-------+
+Output: 
++------+-------+
+| name | bonus |
++------+-------+
+| Brad | null  |
+| John | null  |
+| Dan  | 500   |
++------+-------+
+
diff --git a/leetcode/problem/employees-whose-manager-left-the-company.html b/leetcode/problem/employees-whose-manager-left-the-company.html new file mode 100644 index 00000000..62db0908 --- /dev/null +++ b/leetcode/problem/employees-whose-manager-left-the-company.html @@ -0,0 +1,51 @@ +

Table: Employees

+ +
++-------------+----------+
+| Column Name | Type     |
++-------------+----------+
+| employee_id | int      |
+| name        | varchar  |
+| manager_id  | int      |
+| salary      | int      |
++-------------+----------+
+In SQL, employee_id is the primary key for this table.
+This table contains information about the employees, their salary, and the ID of their manager. Some employees do not have a manager (manager_id is null). 
+
+ +

 

+ +

Find the IDs of the employees whose salary is strictly less than $30000 and whose manager left the company. When a manager leaves the company, their information is deleted from the Employees table, but the reports still have their manager_id set to the manager that left.

+ +

Return the result table ordered by employee_id.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input:  
+Employees table:
++-------------+-----------+------------+--------+
+| employee_id | name      | manager_id | salary |
++-------------+-----------+------------+--------+
+| 3           | Mila      | 9          | 60301  |
+| 12          | Antonella | null       | 31000  |
+| 13          | Emery     | null       | 67084  |
+| 1           | Kalel     | 11         | 21241  |
+| 9           | Mikaela   | null       | 50937  |
+| 11          | Joziah    | 6          | 28485  |
++-------------+-----------+------------+--------+
+Output: 
++-------------+
+| employee_id |
++-------------+
+| 11          |
++-------------+
+
+Explanation: 
+The employees with a salary less than $30000 are 1 (Kalel) and 11 (Joziah).
+Kalel's manager is employee 11, who is still in the company (Joziah).
+Joziah's manager is employee 6, who left the company because there is no row for employee 6 as it was deleted.
+
diff --git a/leetcode/problem/find-users-with-valid-e-mails.html b/leetcode/problem/find-users-with-valid-e-mails.html new file mode 100644 index 00000000..8775cca4 --- /dev/null +++ b/leetcode/problem/find-users-with-valid-e-mails.html @@ -0,0 +1,60 @@ +

Table: Users

+ +
++---------------+---------+
+| Column Name   | Type    |
++---------------+---------+
+| user_id       | int     |
+| name          | varchar |
+| mail          | varchar |
++---------------+---------+
+user_id is the primary key (column with unique values) for this table.
+This table contains information of the users signed up in a website. Some e-mails are invalid.
+
+ +

 

+ +

Write a solution to find the users who have valid emails.

+ +

A valid e-mail has a prefix name and a domain where:

+ +
    +
  • The prefix name is a string that may contain letters (upper or lower case), digits, underscore '_', period '.', and/or dash '-'. The prefix name must start with a letter.
  • +
  • The domain is '@leetcode.com'.
  • +
+ +

Return the result table in any order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+Users table:
++---------+-----------+-------------------------+
+| user_id | name      | mail                    |
++---------+-----------+-------------------------+
+| 1       | Winston   | winston@leetcode.com    |
+| 2       | Jonathan  | jonathanisgreat         |
+| 3       | Annabelle | bella-@leetcode.com     |
+| 4       | Sally     | sally.come@leetcode.com |
+| 5       | Marwan    | quarz#2020@leetcode.com |
+| 6       | David     | david69@gmail.com       |
+| 7       | Shapiro   | .shapo@leetcode.com     |
++---------+-----------+-------------------------+
+Output: 
++---------+-----------+-------------------------+
+| user_id | name      | mail                    |
++---------+-----------+-------------------------+
+| 1       | Winston   | winston@leetcode.com    |
+| 3       | Annabelle | bella-@leetcode.com     |
+| 4       | Sally     | sally.come@leetcode.com |
++---------+-----------+-------------------------+
+Explanation: 
+The mail of user 2 does not have a domain.
+The mail of user 5 has the # sign which is not allowed.
+The mail of user 6 does not have the leetcode domain.
+The mail of user 7 starts with a period.
+