1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 10:38:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
This commit is contained in:
程序员小墨 2023-12-09 18:53:53 +08:00
parent c9b1bf36a8
commit 9bc4722a45
349 changed files with 15897 additions and 0 deletions

View File

@ -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\",\"<p>\\u7248\\u672c\\uff1a<code>Node.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a <code>--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f <a href=\\\"http:\\/\\/node.green\\/\\\" target=\\\"_blank\\\">\\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"<p>TypeScript 5.1.6<\\/p>\\r\\n\\r\\n<p>Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> 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"
}
}
}

View File

@ -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\",\"<p>\\u7248\\u672c\\uff1a<code>Node.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a <code>--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f <a href=\\\"http:\\/\\/node.green\\/\\\" target=\\\"_blank\\\">\\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"<p>TypeScript 5.1.6<\\/p>\\r\\n\\r\\n<p>Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> 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"
}
}
}

View File

@ -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\",\"<p>\\u7248\\u672c\\uff1a<code>Node.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a <code>--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f <a href=\\\"http:\\/\\/node.green\\/\\\" target=\\\"_blank\\\">\\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"<p>TypeScript 5.1.6<\\/p>\\r\\n\\r\\n<p>Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> 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"
}
}
}

View File

@ -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\",\"<p>\\u7248\\u672c\\uff1a<code>Node.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a <code>--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f <a href=\\\"http:\\/\\/node.green\\/\\\" target=\\\"_blank\\\">\\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"<p>TypeScript 5.1.6<\\/p>\\r\\n\\r\\n<p>Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> 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"
}
}
}

View File

@ -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\",\"<p>\\u7248\\u672c\\uff1a<code>Node.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a <code>--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f <a href=\\\"http:\\/\\/node.green\\/\\\" target=\\\"_blank\\\">\\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"<p>TypeScript 5.1.6<\\/p>\\r\\n\\r\\n<p>Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> 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"
}
}
}

View File

@ -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\",\"<p>\\u7248\\u672c\\uff1a<code>Node.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a <code>--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f <a href=\\\"http:\\/\\/node.green\\/\\\" target=\\\"_blank\\\">\\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"<p>TypeScript 5.1.6<\\/p>\\r\\n\\r\\n<p>Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> 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"
}
}
}

View File

@ -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\",\"<p>\\u7248\\u672c\\uff1a<code>Node.js 16.13.2<\\/code><\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5728\\u6267\\u884c\\u65f6\\u5c06\\u5e26\\u4e0a <code>--harmony<\\/code> \\u6807\\u8bb0\\u6765\\u5f00\\u542f <a href=\\\"http:\\/\\/node.green\\/\\\" target=\\\"_blank\\\">\\u65b0\\u7248ES6\\u7279\\u6027<\\/a>\\u3002<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> datastructures-js\\/queue@4.2.1<\\/a>\\u3002<\\/p>\"],\"typescript\":[\"TypeScript\",\"<p>TypeScript 5.1.6<\\/p>\\r\\n\\r\\n<p>Compile Options: --alwaysStrict --strictBindCallApply --strictFunctionTypes --target ES2022<\\/p>\\r\\n\\r\\n<p><a href=\\\"https:\\/\\/lodash.com\\\" target=\\\"_blank\\\">lodash.js<\\/a> \\u5e93\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5305\\u542b\\u3002<\\/p>\\r\\n\\r\\n<p> \\u5982\\u9700\\u4f7f\\u7528\\u961f\\u5217\\/\\u4f18\\u5148\\u961f\\u5217\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/priority-queue\\/tree\\/fb4fdb984834421279aeb081df7af624d17c2a03\\\" target=\\\"_blank\\\"> datastructures-js\\/priority-queue@5.3.0<\\/a> \\u548c <a href=\\\"https:\\/\\/github.com\\/datastructures-js\\/queue\\/tree\\/e63563025a5a805aa16928cb53bcd517bfea9230\\\" target=\\\"_blank\\\"> 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"
}
}
}

View File

@ -0,0 +1,97 @@
{
"data": {
"question": {
"questionId": "1390",
"questionFrontendId": "1251",
"categoryTitle": "Database",
"boundTopicId": 41811,
"title": "Average Selling Price",
"titleSlug": "average-selling-price",
"content": "<p>Table: <code>Prices</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Table: <code>UnitsSold</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Write a solution to find the average selling price for each product. <code>average_price</code> should be <strong>rounded to 2 decimal places</strong>.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The&nbsp;result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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<strong>Output:</strong> \n+------------+---------------+\n| product_id | average_price |\n+------------+---------------+\n| 1 | 6.96 |\n| 2 | 16.96 |\n+------------+---------------+\n<strong>Explanation:</strong> \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</pre>\n",
"translatedTitle": "平均售价",
"translatedContent": "<p>表:<code>Prices</code></p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| product_id | int |\n| start_date | date |\n| end_date | date |\n| price | int |\n+---------------+---------+\n(product_idstart_dateend_date) 是 <code>prices</code> 表的主键(具有唯一值的列的组合)。\n<code>prices</code> 表的每一行表示的是某个产品在一段时期内的价格。\n每个产品的对应时间段是不会重叠的这也意味着同一个产品的价格时段不会出现交叉。</pre>\n\n<p>&nbsp;</p>\n\n<p>表:<code>UnitsSold</code></p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| product_id | int |\n| purchase_date | date |\n| units | int |\n+---------------+---------+\n<span style=\"white-space: pre-wrap;\">该表可能包含重复数据</span>。\n<span style=\"white-space: pre-wrap;\">该</span>表的每一行表示的是每种产品的出售日期,单位和产品 id。</pre>\n\n<p>&nbsp;</p>\n\n<p>编写解决方案以查找每种产品的平均售价。<code>average_price</code> 应该 <strong>四舍五入到小数点后两位</strong>。</p>\n\n<p>返回结果表 <strong>无顺序要求</strong> 。</p>\n\n<p>结果格式如下例所示。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>\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<strong>输出:</strong>\n+------------+---------------+\n| product_id | average_price |\n+------------+---------------+\n| 1 | 6.96 |\n| 2 | 16.96 |\n+------------+---------------+\n<strong>解释:</strong>\n平均售价 = 产品总价 / 销售的产品数量。\n产品 1 的平均售价 = ((100 * 5)+(15 * 20) )/ 115 = 6.96\n产品 2 的平均售价 = ((200 * 15)+(30 * 30) )/ 230 = 16.96</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -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": "<p>Table: <code>Activity</code></p>\n\n<pre>\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 (&#39;start&#39;, &#39;end&#39;).\ntimestamp is a float representing the current time in seconds.\n&#39;start&#39; means the machine starts the process at the given timestamp and &#39;end&#39; means the machine ends the process at the given timestamp.\nThe &#39;start&#39; timestamp will always be before the &#39;end&#39; timestamp for every (machine_id, process_id) pair.</pre>\n\n<p>&nbsp;</p>\n\n<p>There is a factory website that has several machines each running the <strong>same number of processes</strong>. Write a solution&nbsp;to find the <strong>average time</strong> each machine takes to complete a process.</p>\n\n<p>The time to complete a process is the <code>&#39;end&#39; timestamp</code> minus the <code>&#39;start&#39; timestamp</code>. 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.</p>\n\n<p>The resulting table should have the <code>machine_id</code> along with the <strong>average time</strong> as <code>processing_time</code>, which should be <strong>rounded to 3 decimal places</strong>.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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<strong>Output:</strong> \n+------------+-----------------+\n| machine_id | processing_time |\n+------------+-----------------+\n| 0 | 0.894 |\n| 1 | 0.995 |\n| 2 | 1.456 |\n+------------+-----------------+\n<strong>Explanation:</strong> \nThere are 3 machines running 2 processes each.\nMachine 0&#39;s average time is ((1.520 - 0.712) + (4.120 - 3.140)) / 2 = 0.894\nMachine 1&#39;s average time is ((1.550 - 0.550) + (1.420 - 0.430)) / 2 = 0.995\nMachine 2&#39;s average time is ((4.512 - 4.100) + (5.000 - 2.500)) / 2 = 1.456\n</pre>\n",
"translatedTitle": "每台机器的进程平均运行时间",
"translatedContent": "<p>表: <code>Activity</code></p>\n\n<pre>\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同一台机器同一个进程都有一对开始时间戳和结束时间戳而且开始时间戳永远在结束时间戳前面。</pre>\n\n<p>&nbsp;</p>\n\n<p>现在有一个工厂网站由几台机器运行,每台机器上运行着 <strong>相同数量的进程</strong> 。编写解决方案,计算每台机器各自完成一个进程任务的平均耗时。</p>\n\n<p>完成一个进程任务的时间指进程的<code>'end' 时间戳</code> 减去&nbsp;<code>'start' 时间戳</code>。平均耗时通过计算每台机器上所有进程任务的总耗费时间除以机器上的总进程数量获得。</p>\n\n<p>结果表必须包含<code>machine_id机器ID</code> 和对应的&nbsp;<strong>average time平均耗时</strong>&nbsp;别名&nbsp;<code>processing_time</code>,且<strong>四舍五入保留3位小数。</strong></p>\n\n<p>以 <strong>任意顺序</strong> 返回表。</p>\n\n<p>具体参考例子如下。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>\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<strong>输出:</strong>\n+------------+-----------------+\n| machine_id | processing_time |\n+------------+-----------------+\n| 0 | 0.894 |\n| 1 | 0.995 |\n| 2 | 1.456 |\n+------------+-----------------+\n<strong>解释:</strong>\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</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -0,0 +1,95 @@
{
"data": {
"question": {
"questionId": "619",
"questionFrontendId": "619",
"categoryTitle": "Database",
"boundTopicId": 2630,
"title": "Biggest Single Number",
"titleSlug": "biggest-single-number",
"content": "<p>Table: <code>MyNumbers</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>A <strong>single number</strong> is a number that appeared only once in the <code>MyNumbers</code> table.</p>\n\n<p>Find the largest <strong>single number</strong>. If there is no <strong>single number</strong>, report <code>null</code>.</p>\n\n<p>The result format is in the following example.</p>\n<ptable> </ptable>\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nMyNumbers table:\n+-----+\n| num |\n+-----+\n| 8 |\n| 8 |\n| 3 |\n| 3 |\n| 1 |\n| 4 |\n| 5 |\n| 6 |\n+-----+\n<strong>Output:</strong> \n+-----+\n| num |\n+-----+\n| 6 |\n+-----+\n<strong>Explanation:</strong> The single numbers are 1, 4, 5, and 6.\nSince 6 is the largest single number, we return it.\n</pre>\n\n<p><strong class=\"example\">Example 2:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nMyNumbers table:\n+-----+\n| num |\n+-----+\n| 8 |\n| 8 |\n| 7 |\n| 7 |\n| 3 |\n| 3 |\n| 3 |\n+-----+\n<strong>Output:</strong> \n+------+\n| num |\n+------+\n| null |\n+------+\n<strong>Explanation:</strong> There are no single numbers in the input table so we return null.\n</pre>\n",
"translatedTitle": "只出现一次的最大数字",
"translatedContent": "<p><code>MyNumbers</code> 表:</p>\n\n<div class=\"original__bRMd\">\n<div>\n<pre>\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| num | int |\n+-------------+------+\n该表可能包含重复项换句话说在SQL中该表没有主键。\n这张表的每一行都含有一个整数。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>单一数字</strong> 是在 <code>MyNumbers</code> 表中只出现一次的数字。</p>\n\n<p>找出最大的 <strong>单一数字</strong> 。如果不存在 <strong>单一数字</strong> ,则返回&nbsp;<code>null</code> 。</p>\n\n<p>查询结果如下例所示。</p>\n<ptable> </ptable>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>\nMyNumbers 表:\n+-----+\n| num |\n+-----+\n| 8 |\n| 8 |\n| 3 |\n| 3 |\n| 1 |\n| 4 |\n| 5 |\n| 6 |\n+-----+\n<strong>输出:</strong>\n+-----+\n| num |\n+-----+\n| 6 |\n+-----+\n<strong>解释:</strong>单一数字有 1、4、5 和 6 。\n6 是最大的单一数字,返回 6 。\n</pre>\n\n<p><strong>示例 2</strong></p>\n\n<pre>\n<strong>输入:</strong>\nMyNumbers table:\n+-----+\n| num |\n+-----+\n| 8 |\n| 8 |\n| 7 |\n| 7 |\n| 3 |\n| 3 |\n| 3 |\n+-----+\n<strong>输出:</strong>\n+------+\n| num |\n+------+\n| null |\n+------+\n<strong>解释:</strong>输入的表中不存在单一数字,所以返回 null 。\n</pre>\n</div>\n</div>\n\n<p>&nbsp;</p>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -0,0 +1,100 @@
{
"data": {
"question": {
"questionId": "2087",
"questionFrontendId": "1934",
"categoryTitle": "Database",
"boundTopicId": 878355,
"title": "Confirmation Rate",
"titleSlug": "confirmation-rate",
"content": "<p>Table: <code>Signups</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Table: <code>Confirmations</code></p>\n\n<pre>\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 (&#39;confirmed&#39;, &#39;timeout&#39;)\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 (&#39;confirmed&#39;) or expired without confirming (&#39;timeout&#39;).\n</pre>\n\n<p>&nbsp;</p>\n\n<p>The <strong>confirmation rate</strong> of a user is the number of <code>&#39;confirmed&#39;</code> messages divided by the total number of requested confirmation messages. The confirmation rate of a user that did not request any confirmation messages is <code>0</code>. Round the confirmation rate to <strong>two decimal</strong> places.</p>\n\n<p>Write a solution to find the <strong>confirmation rate</strong> of each user.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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+---------+---------------------+-----------+\n<strong>Output:</strong> \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<strong>Explanation:</strong> \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</pre>\n",
"translatedTitle": "确认率",
"translatedContent": "<p>表: <code>Signups</code></p>\n\n<pre>\n+----------------+----------+\n| Column Name | Type |\n+----------------+----------+\n| user_id | int |\n| time_stamp | datetime |\n+----------------+----------+\nUser_id是该表的主键。\n每一行都包含ID为user_id的用户的注册时间信息。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>表: <code>Confirmations</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>用户的 <strong>确认率</strong>&nbsp;是 <code>'confirmed'</code>&nbsp;消息的数量除以请求的确认消息的总数。没有请求任何确认消息的用户的确认率为&nbsp;<code>0</code> 。确认率四舍五入到 <strong>小数点后两位</strong> 。</p>\n\n<p>编写一个SQL查询来查找每个用户的 确认率 。<br />\n<br />\n以 任意顺序&nbsp;返回结果表。<br />\n<br />\n查询结果格式如下所示。<br />\n<br />\n<strong>示例1:</strong></p>\n\n<pre>\n<b>输入:</b>\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<strong>输出:</strong> \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<strong>解释:\n</strong>用户 6 没有请求任何确认消息。确认率为 0。\n用户 3 进行了 2 次请求,都超时了。确认率为 0。\n用户 7 提出了 3 个请求,所有请求都得到了确认。确认率为 1。\n用户 2 做了 2 个请求,其中一个被确认,另一个超时。确认率为 1 / 2 = 0.5。</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -0,0 +1,91 @@
{
"data": {
"question": {
"questionId": "2057",
"questionFrontendId": "1907",
"categoryTitle": "Database",
"boundTopicId": 841394,
"title": "Count Salary Categories",
"titleSlug": "count-salary-categories",
"content": "<p>Table: <code>Accounts</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Write a solution&nbsp;to calculate the number of bank accounts for each salary category. The salary categories are:</p>\n\n<ul>\n\t<li><code>&quot;Low Salary&quot;</code>: All the salaries <strong>strictly less</strong> than <code>$20000</code>.</li>\n\t<li><code>&quot;Average Salary&quot;</code>: All the salaries in the <strong>inclusive</strong> range <code>[$20000, $50000]</code>.</li>\n\t<li><code>&quot;High Salary&quot;</code>: All the salaries <strong>strictly greater</strong> than <code>$50000</code>.</li>\n</ul>\n\n<p>The result table <strong>must</strong> contain all three categories. If there are no accounts in a category,&nbsp;return&nbsp;<code>0</code>.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The&nbsp;result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nAccounts table:\n+------------+--------+\n| account_id | income |\n+------------+--------+\n| 3 | 108939 |\n| 2 | 12747 |\n| 8 | 87709 |\n| 6 | 91796 |\n+------------+--------+\n<strong>Output:</strong> \n+----------------+----------------+\n| category | accounts_count |\n+----------------+----------------+\n| Low Salary | 1 |\n| Average Salary | 0 |\n| High Salary | 3 |\n+----------------+----------------+\n<strong>Explanation:</strong> \nLow Salary: Account 2.\nAverage Salary: No accounts.\nHigh Salary: Accounts 3, 6, and 8.\n</pre>\n",
"translatedTitle": "按分类统计薪水",
"translatedContent": "<p>表: <code>Accounts</code></p>\n\n<pre>\n+-------------+------+\n| 列名 | 类型 |\n+-------------+------+\n| account_id | int |\n| income | int |\n+-------------+------+\n在 SQL 中account_id&nbsp;是这个表的主键。\n每一行都包含一个银行帐户的月收入的信息。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>查询每个工资类别的银行账户数量。&nbsp;工资类别如下:</p>\n\n<ul>\n\t<li><code>\"Low Salary\"</code>:所有工资 <strong>严格低于</strong> <code>20000</code> 美元。</li>\n\t<li><code>\"Average Salary\"</code> <strong>包含</strong> 范围内的所有工资&nbsp;<code>[$20000,&nbsp;$50000]</code> 。</li>\n\t<li>\n\t<p><code>\"High Salary\"</code>:所有工资 <strong>严格大于</strong> <code>50000</code> 美元。</p>\n\t</li>\n</ul>\n\n<p>结果表 <strong>必须</strong> 包含所有三个类别。&nbsp;如果某个类别中没有帐户,则报告&nbsp;<code>0</code> 。</p>\n\n<p>按 <strong>任意顺序</strong> 返回结果表。</p>\n\n<p>查询结果格式如下示例。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<b>输入:</b>\nAccounts 表:\n+------------+--------+\n| account_id | income |\n+------------+--------+\n| 3 | 108939 |\n| 2 | 12747 |\n| 8 | 87709 |\n| 6 | 91796 |\n+------------+--------+\n<strong>输出:</strong>\n+----------------+----------------+\n| category | accounts_count |\n+----------------+----------------+\n| Low Salary | 1 |\n| Average Salary | 0 |\n| High Salary | 3 |\n+----------------+----------------+\n<strong>解释:</strong>\n低薪: 有一个账户 2.\n中等薪水: 没有.\n高薪: 有三个账户,他们是 3, 6和 8.</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -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": "<p>Table: <code>Customer</code></p>\n\n<pre>\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| customer_id | int |\n| product_key | int |\n+-------------+---------+\nThis table may contain duplicates rows. \n<code>customer_id</code> is not NULL<code>.</code>\nproduct_key is a foreign key (reference column) to <code>Product</code> table.\n</pre>\n\n<p>&nbsp;</p>\n\n<p>Table: <code>Product</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Write a solution to report the customer ids from the <code>Customer</code> table that bought all the products in the <code>Product</code> table.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The&nbsp;result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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+-------------+\n<strong>Output:</strong> \n+-------------+\n| customer_id |\n+-------------+\n| 1 |\n| 3 |\n+-------------+\n<strong>Explanation:</strong> \nThe customers who bought all the products (5 and 6) are customers with IDs 1 and 3.\n</pre>\n",
"translatedTitle": "买下所有产品的客户",
"translatedContent": "<p><code>Customer</code>&nbsp;表:</p>\n\n<pre>\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| customer_id | int |\n| product_key | int |\n+-------------+---------+\n该表可能包含重复的行。\ncustomer_id 不为 NULL。\nproduct_key 是 Product 表的外键(reference 列)。\n</pre>\n\n<p><code>Product</code>&nbsp;表:</p>\n\n<pre>\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| product_key | int |\n+-------------+---------+\nproduct_key 是这张表的主键(具有唯一值的列)。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>编写解决方案,报告&nbsp;<code>Customer</code> 表中购买了 <code>Product</code> 表中所有产品的客户的 id。</p>\n\n<p>返回结果表 <strong>无顺序要求</strong> 。</p>\n\n<p>返回结果格式如下所示。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>\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<strong>输出:</strong>\n+-------------+\n| customer_id |\n+-------------+\n| 1 |\n| 3 |\n+-------------+\n<strong>解释:</strong>\n购买了所有产品5 和 6的客户的 id 是 1 和 3 。\n</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -0,0 +1,98 @@
{
"data": {
"question": {
"questionId": "577",
"questionFrontendId": "577",
"categoryTitle": "Database",
"boundTopicId": 1998,
"title": "Employee Bonus",
"titleSlug": "employee-bonus",
"content": "<p>Table: <code>Employee</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Table: <code>Bonus</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Write a solution to report the name and bonus amount of each employee with a bonus <strong>less than</strong> <code>1000</code>.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The&nbsp;result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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<strong>Output:</strong> \n+------+-------+\n| name | bonus |\n+------+-------+\n| Brad | null |\n| John | null |\n| Dan | 500 |\n+------+-------+\n</pre>\n",
"translatedTitle": "员工奖金",
"translatedContent": "<p>表:<code>Employee</code>&nbsp;</p>\n\n<pre>\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| empId | int |\n| name | varchar |\n| supervisor | int |\n| salary | int |\n+-------------+---------+\nempId 是该表中具有唯一值的列。\n该表的每一行都表示员工的姓名和 id以及他们的工资和经理的 id。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>表:<code>Bonus</code></p>\n\n<pre>\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| empId | int |\n| bonus | int |\n+-------------+------+\nempId 是该表具有唯一值的列。\nempId 是 Employee 表中 empId 的外键(reference 列)。\n该表的每一行都包含一个员工的 id 和他们各自的奖金。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>编写解决方案,报告每个奖金 <strong>少于</strong> <code>1000</code> 的员工的姓名和奖金数额。</p>\n\n<p>以 <strong>任意顺序</strong> 返回结果表。</p>\n\n<p>结果格式如下所示。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<b>输入:</b>\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<b>输出:</b>\n+------+-------+\n| name | bonus |\n+------+-------+\n| Brad | null |\n| John | null |\n| Dan | 500 |\n+------+-------+</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -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": "<p>Table: <code>Employees</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Find the IDs of the employees whose salary is strictly less than <code>$30000</code> and whose manager left the company. When a manager leaves the company, their information is deleted from the <code>Employees</code> table, but the reports still have their <code>manager_id</code> set to the manager that left.</p>\n\n<p>Return the result table ordered by <code>employee_id</code>.</p>\n\n<p>The result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input: </strong> \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<strong>Output:</strong> \n+-------------+\n| employee_id |\n+-------------+\n| 11 |\n+-------------+\n\n<strong>Explanation:</strong> \nThe employees with a salary less than $30000 are 1 (Kalel) and 11 (Joziah).\nKalel&#39;s manager is employee 11, who is still in the company (Joziah).\nJoziah&#39;s manager is employee 6, who left the company because there is no row for employee 6 as it was deleted.\n</pre>\n",
"translatedTitle": "上级经理已离职的公司员工",
"translatedContent": "<p>表: <code>Employees</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>查找这些员工的id他们的薪水严格少于<code>$30000</code>&nbsp;并且他们的上级经理已离职。当一个经理离开公司时,他们的信息需要从员工表中删除掉,但是表中的员工的<code>manager_id</code> &nbsp;这一列还是设置的离职经理的id&nbsp;。</p>\n\n<p>返回的结果按照<code>employee_id&nbsp;</code>从小到大排序。</p>\n\n<p>查询结果如下所示:</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例:</strong></p>\n\n<pre>\n<strong>输入:</strong>\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<strong>输出:</strong>\n+-------------+\n| employee_id |\n+-------------+\n| 11 |\n+-------------+\n\n<strong>解释:</strong>\n薪水少于 30000 美元的员工有 1 号(Kalel) 和 11号 (Joziah)。\nKalel 的上级经理是 11 号员工,他还在公司上班(他是 Joziah )。\nJoziah 的上级经理是 6 号员工,他已经离职,因为员工表里面已经没有 6 号员工的信息了,它被删除了。\n</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -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": "<p>Table: <code>Users</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Write a solution to find the users who have <strong>valid emails</strong>.</p>\n\n<p>A valid e-mail has a prefix name and a domain where:</p>\n\n<ul>\n\t<li><strong>The prefix name</strong> is a string that may contain letters (upper or lower case), digits, underscore <code>&#39;_&#39;</code>, period <code>&#39;.&#39;</code>, and/or dash <code>&#39;-&#39;</code>. The prefix name <strong>must</strong> start with a letter.</li>\n\t<li><strong>The domain</strong> is <code>&#39;@leetcode.com&#39;</code>.</li>\n</ul>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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+---------+-----------+-------------------------+\n<strong>Output:</strong> \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<strong>Explanation:</strong> \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</pre>\n",
"translatedTitle": "查找拥有有效邮箱的用户",
"translatedContent": "<p>表: <code>Users</code></p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| user_id | int |\n| name | varchar |\n| mail | varchar |\n+---------------+---------+\nuser_id 是该表的主键(具有唯一值的列)。\n该表包含了网站已注册用户的信息。有一些电子邮件是无效的。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>编写一个解决方案,以查找具有有效电子邮件的用户。</p>\n\n<p>一个有效的电子邮件具有前缀名称和域,其中:</p>\n\n<ol>\n\t<li>&nbsp;<strong>前缀</strong> 名称是一个字符串,可以包含字母(大写或小写),数字,下划线 <code>'_'</code> ,点 <code>'.'</code> 和/或破折号 <code>'-'</code> 。前缀名称 <strong>必须</strong> 以字母开头。</li>\n\t<li><strong>域</strong> 为 <code>'@leetcode.com'</code> 。</li>\n</ol>\n\n<p>以任何顺序返回结果表。</p>\n\n<p>结果的格式如以下示例所示:</p>\n\n<p>&nbsp;</p>\n\n<p><strong class=\"example\">示例 1</strong></p>\n\n<pre>\n<b>输入:</b>\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<b>输出:</b>\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<b>解释:</b>\n用户 2 的电子邮件没有域。 \n用户 5 的电子邮件带有不允许的 '#' 符号。\n用户 6 的电子邮件没有 leetcode 域。 \n用户 7 的电子邮件以点开头。\n</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -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": "<p>Table: <code>RequestAccepted</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Write a solution to find the people who have the most friends and the most friends number.</p>\n\n<p>The test cases are generated so that only one person has the most friends.</p>\n\n<p>The result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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+--------------+-------------+-------------+\n<strong>Output:</strong> \n+----+-----+\n| id | num |\n+----+-----+\n| 3 | 3 |\n+----+-----+\n<strong>Explanation:</strong> \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</pre>\n\n<p>&nbsp;</p>\n<p><strong>Follow up:</strong> In the real world, multiple people could have the same most number of friends. Could you find all these people in this case?</p>\n",
"translatedTitle": "好友申请 II :谁有最多的好友",
"translatedContent": "<p><code>RequestAccepted</code> 表:</p>\n\n<div class=\"original__bRMd\">\n<div>\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>编写解决方案,找出拥有最多的好友的人和他拥有的好友数目。</p>\n\n<p>生成的测试用例保证拥有最多好友数目的只有 1 个人。</p>\n\n<p>查询结果格式如下例所示。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>\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<strong>输出:</strong>\n+----+-----+\n| id | num |\n+----+-----+\n| 3 | 3 |\n+----+-----+\n<strong>解释:</strong>\n编号为 3 的人是编号为 1 2 和 4 的人的好友,所以他总共有 3 个好友,比其他人都多。</pre>\n\n<p>&nbsp;</p>\n\n<p><strong>进阶:</strong>在真实世界里,可能会有多个人拥有好友数相同且最多,你能找到所有这些人吗?</p>\n</div>\n</div>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -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": "<p>Table: <code>Activity</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Write a&nbsp;solution&nbsp;to report the <strong>fraction</strong> of players that logged in again on the day after the day they first logged in, <strong>rounded to 2 decimal places</strong>. 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.</p>\n\n<p>The&nbsp;result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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<strong>Output:</strong> \n+-----------+\n| fraction |\n+-----------+\n| 0.33 |\n+-----------+\n<strong>Explanation:</strong> \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</pre>\n",
"translatedTitle": "游戏玩法分析 IV",
"translatedContent": "<p>Table:&nbsp;<code>Activity</code></p>\n\n<pre>\n+--------------+---------+\n| Column Name | Type |\n+--------------+---------+\n| player_id | int |\n| device_id | int |\n| event_date | date |\n| games_played | int |\n+--------------+---------+\nplayer_idevent_date是此表的主键具有唯一值的列的组合。\n这张表显示了某些游戏的玩家的活动情况。\n每一行是一个玩家的记录他在某一天使用某个设备注销之前登录并玩了很多游戏可能是 0。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>编写解决方案,报告在首次登录的第二天再次登录的玩家的 <strong>比率</strong><strong>四舍五入到小数点后两位</strong>。换句话说,你需要计算从首次登录日期开始至少连续两天登录的玩家的数量,然后除以玩家总数。</p>\n\n<p>结果格式如下所示:</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>\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<strong>输出:</strong>\n+-----------+\n| fraction |\n+-----------+\n| 0.33 |\n+-----------+\n<strong>解释:</strong>\n只有 ID 为 1 的玩家在第一天登录后才重新登录,所以答案是 1/3 = 0.33\n</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -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": "<p>Table: <code>Delivery</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>If the customer&#39;s preferred delivery date is the same as the order date, then the order is called <strong>immediate;</strong> otherwise, it is called <strong>scheduled</strong>.</p>\n\n<p>The <strong>first order</strong> 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.</p>\n\n<p>Write a solution to find the percentage of immediate orders in the first orders of all customers, <strong>rounded to 2 decimal places</strong>.</p>\n\n<p>The&nbsp;result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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+-------------+-------------+------------+-----------------------------+\n<strong>Output:</strong> \n+----------------------+\n| immediate_percentage |\n+----------------------+\n| 50.00 |\n+----------------------+\n<strong>Explanation:</strong> \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</pre>\n",
"translatedTitle": "即时食物配送 II",
"translatedContent": "<p>配送表: <code>Delivery</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>如果顾客期望的配送日期和下单日期相同,则该订单称为 「<strong>即时订单</strong>」,否则称为「<strong>计划订单</strong>」。</p>\n\n<p>「<strong>首次订单</strong>」是顾客最早创建的订单。我们保证一个顾客只会有一个「首次订单」。</p>\n\n<p>编写解决方案以获取即时订单在所有用户的首次订单中的比例。<strong>保留两位小数。</strong></p>\n\n<p>结果示例如下所示:</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>\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<strong>输出:</strong>\n+----------------------+\n| immediate_percentage |\n+----------------------+\n| 50.00 |\n+----------------------+\n<strong>解释:</strong>\n1 号顾客的 1 号订单是首次订单,并且是计划订单。\n2 号顾客的 2 号订单是首次订单,并且是即时订单。\n3 号顾客的 5 号订单是首次订单,并且是计划订单。\n4 号顾客的 7 号订单是首次订单,并且是即时订单。\n因此一半顾客的首次订单是即时的。\n</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -0,0 +1,89 @@
{
"data": {
"question": {
"questionId": "1827",
"questionFrontendId": "1683",
"categoryTitle": "Database",
"boundTopicId": 517777,
"title": "Invalid Tweets",
"titleSlug": "invalid-tweets",
"content": "<p>Table: <code>Tweets</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>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 <strong>strictly greater</strong> than <code>15</code>.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nTweets table:\n+----------+----------------------------------+\n| tweet_id | content |\n+----------+----------------------------------+\n| 1 | Vote for Biden |\n| 2 | Let us make America great again! |\n+----------+----------------------------------+\n<strong>Output:</strong> \n+----------+\n| tweet_id |\n+----------+\n| 2 |\n+----------+\n<strong>Explanation:</strong> \nTweet 1 has length = 14. It is a valid tweet.\nTweet 2 has length = 32. It is an invalid tweet.\n</pre>\n",
"translatedTitle": "无效的推文",
"translatedContent": "<p>表:<code>Tweets</code></p>\n\n<pre>\n+----------------+---------+\n| Column Name | Type |\n+----------------+---------+\n| tweet_id | int |\n| content | varchar |\n+----------------+---------+\n在 SQL 中tweet_id 是这个表的主键。\n这个表包含某社交媒体 App 中所有的推文。</pre>\n\n<p>&nbsp;</p>\n\n<p>查询所有无效推文的编号ID。当推文内容中的字符数<strong>严格大于</strong> <code>15</code> 时,该推文是无效的。</p>\n\n<p>以<strong>任意顺序</strong>返回结果表。</p>\n\n<p>查询结果格式如下所示:</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>\nTweets 表:\n+----------+----------------------------------+\n| tweet_id | content |\n+----------+----------------------------------+\n| 1 | Vote for Biden |\n| 2 | Let us make America great again! |\n+----------+----------------------------------+\n\n<strong>输出:</strong>\n+----------+\n| tweet_id |\n+----------+\n| 2 |\n+----------+\n<strong>解释:</strong>\n推文 1 的长度 length = 14。该推文是有效的。\n推文 2 的长度 length = 32。该推文是无效的。\n</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -0,0 +1,93 @@
{
"data": {
"question": {
"questionId": "585",
"questionFrontendId": "585",
"categoryTitle": "Database",
"boundTopicId": 2643,
"title": "Investments in 2016",
"titleSlug": "investments-in-2016",
"content": "<p>Table: <code>Insurance</code></p>\n\n<pre>\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&#39;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&#39;s city. It&#39;s guaranteed that lat is not NULL.\nlon is the longitude of the policy holder&#39;s city. It&#39;s guaranteed that lon is not NULL.\n</pre>\n\n<p>&nbsp;</p>\n\n<p>Write a solution to report the sum of all total investment values in 2016 <code>tiv_2016</code>, for all policyholders who:</p>\n\n<ul>\n\t<li>have the same <code>tiv_2015</code> value as one or more other policyholders, and</li>\n\t<li>are not located in the same city as any other policyholder (i.e., the (<code>lat, lon</code>) attribute pairs must be unique).</li>\n</ul>\n\n<p>Round <code>tiv_2016</code> to <strong>two decimal places</strong>.</p>\n\n<p>The&nbsp;result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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+-----+----------+----------+-----+-----+\n<strong>Output:</strong> \n+----------+\n| tiv_2016 |\n+----------+\n| 45.00 |\n+----------+\n<strong>Explanation:</strong> \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</pre>\n",
"translatedTitle": "2016年的投资",
"translatedContent": "<p><code>Insurance</code> 表:</p>\n\n<div class=\"original__bRMd\">\n<div>\n<pre>\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 不为空。</pre>\n\n<p>&nbsp;</p>\n\n<p>编写解决方案报告 2016 年 (<code>tiv_2016</code>) 所有满足下述条件的投保人的投保金额之和:</p>\n\n<ul>\n\t<li>他在 2015 年的投保额&nbsp;(<code>tiv_2015</code>) 至少跟一个其他投保人在 2015 年的投保额相同。</li>\n\t<li>他所在的城市必须与其他投保人都不同(也就是说&nbsp;(<code>lat, lon</code>) 不能跟其他任何一个投保人完全相同)。</li>\n</ul>\n\n<p><code>tiv_2016</code> 四舍五入的 <strong>两位小数</strong> 。</p>\n\n<p>查询结果格式如下例所示。</p>\n\n<p>&nbsp;</p>\n\n<p><strong class=\"example\">示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>\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<strong>输出:</strong>\n+----------+\n| tiv_2016 |\n+----------+\n| 45.00 |\n+----------+\n<strong>解释:\n</strong>表中的第一条记录和最后一条记录都满足两个条件。\ntiv_2015 值为 10 与第三条和第四条记录相同,且其位置是唯一的。\n\n第二条记录不符合任何一个条件。其 tiv_2015 与其他投保人不同,并且位置与第三条记录相同,这也导致了第三条记录不符合题目要求。\n因此结果是第一条记录和最后一条记录的 tiv_2016 之和,即 45 。</pre>\n</div>\n</div>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -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": "<p>Table: <code>Queue</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>There is a queue of people waiting to board a bus. However, the bus has a weight limit of <code>1000</code><strong> kilograms</strong>, so there may be some people who cannot board.</p>\n\n<p>Write a solution to find the <code>person_name</code> of the <strong>last person</strong> 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.</p>\n\n<p>The&nbsp;result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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+-----------+-------------+--------+------+\n<strong>Output:</strong> \n+-------------+\n| person_name |\n+-------------+\n| John Cena |\n+-------------+\n<strong>Explanation:</strong> 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</pre>\n",
"translatedTitle": "最后一个能进入巴士的人",
"translatedContent": "<p>表: <code>Queue</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>有一队乘客在等着上巴士。然而,巴士有<code>1000</code>&nbsp; <strong>千克</strong> 的重量限制,所以其中一部分乘客可能无法上巴士。</p>\n\n<p>编写解决方案找出 <strong>最后一个</strong> 上巴士且不超过重量限制的乘客,并报告 <code>person_name</code> 。题目测试用例确保顺位第一的人可以上巴士且不会超重。</p>\n\n<p>返回结果格式如下所示。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>\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<strong>输出:</strong>\n+-------------+\n| person_name |\n+-------------+\n| John Cena |\n+-------------+\n<strong>解释:</strong>\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+------+----+-----------+--------+--------------+</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

File diff suppressed because one or more lines are too long

View File

@ -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": "<p>Table: <code>Products</code></p>\n\n<pre>\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&#39;s products.\n</pre>\n\n<p>&nbsp;</p>\n\n<p>Table: <code>Orders</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Write a solution to get the names of products that have at least <code>100</code> units ordered in <strong>February 2020</strong> and their amount.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The&nbsp;result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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+--------------+--------------+----------+\n<strong>Output:</strong> \n+--------------------+---------+\n| product_name | unit |\n+--------------------+---------+\n| Leetcode Solutions | 130 |\n| Leetcode Kit | 100 |\n+--------------------+---------+\n<strong>Explanation:</strong> \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</pre>\n",
"translatedTitle": "列出指定时间段内所有的下单产品",
"translatedContent": "<p>表: <code>Products</code></p>\n\n<pre>\n+------------------+---------+\n| Column Name | Type |\n+------------------+---------+\n| product_id | int |\n| product_name | varchar |\n| product_category | varchar |\n+------------------+---------+\nproduct_id 是该表主键(具有唯一值的列)。\n该表包含该公司产品的数据。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>表: <code>Orders</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>写一个解决方案,要求获取在 2020 年 2 月份下单的数量不少于 100 的产品的名字和数目。</p>\n\n<p>返回结果表单的 <strong>顺序无要求 </strong>。</p>\n\n<p>查询结果的格式如下。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>\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<strong>输出:</strong>\n+--------------------+---------+\n| product_name | unit |\n+--------------------+---------+\n| Leetcode Solutions | 130 |\n| Leetcode Kit | 100 |\n+--------------------+---------+\n<strong>解释:</strong>\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 。</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -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": "<p>Table: <code>Employee</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Write a solution to find managers with at least <strong>five direct reports</strong>.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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+-----+-------+------------+-----------+\n<strong>Output:</strong> \n+------+\n| name |\n+------+\n| John |\n+------+\n</pre>\n",
"translatedTitle": "至少有5名直接下属的经理",
"translatedContent": "<p>表:&nbsp;<code>Employee</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>编写一个解决方案,找出至少有<strong>五个直接下属</strong>的经理。</p>\n\n<p>以 <strong>任意顺序 </strong>返回结果表。</p>\n\n<p>查询结果格式如下所示。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong> \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<strong>输出:</strong> \n+------+\n| name |\n+------+\n| John |\n+------+</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -0,0 +1,91 @@
{
"data": {
"question": {
"questionId": "1317",
"questionFrontendId": "1193",
"categoryTitle": "Database",
"boundTopicId": 27992,
"title": "Monthly Transactions I",
"titleSlug": "monthly-transactions-i",
"content": "<p>Table: <code>Transactions</code></p>\n\n<pre>\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 [&quot;approved&quot;, &quot;declined&quot;].\n</pre>\n\n<p>&nbsp;</p>\n\n<p>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.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The query result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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<strong>Output:</strong> \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</pre>\n",
"translatedTitle": "每月交易 I",
"translatedContent": "<p>表:<code>Transactions</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>编写一个 sql 查询来查找每个月和每个国家/地区的事务数及其总金额、已批准的事务数及其总金额。</p>\n\n<p>以 <strong>任意顺序</strong> 返回结果表。</p>\n\n<p>查询结果格式如下所示。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<code><strong>输入:</strong>\nTransactions</code> 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<strong>输出:</strong>\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+----------+---------+-------------+----------------+--------------------+-----------------------+</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -0,0 +1,107 @@
{
"data": {
"question": {
"questionId": "1480",
"questionFrontendId": "1341",
"categoryTitle": "Database",
"boundTopicId": 90536,
"title": "Movie Rating",
"titleSlug": "movie-rating",
"content": "<p>Table: <code>Movies</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Table: <code>Users</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Table: <code>MovieRating</code></p>\n\n<pre>\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)&nbsp;for this table.\nThis table contains the rating of a movie by a user in their review.\ncreated_at is the user&#39;s review date. \n</pre>\n\n<p>&nbsp;</p>\n\n<p>Write a solution to:</p>\n\n<ul>\n\t<li>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.</li>\n\t<li>Find the movie name with the <strong>highest average</strong> rating in <code>February 2020</code>. In case of a tie, return the lexicographically smaller movie name.</li>\n</ul>\n\n<p>The&nbsp;result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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+-------------+--------------+--------------+-------------+\n<strong>Output:</strong> \n+--------------+\n| results |\n+--------------+\n| Daniel |\n| Frozen 2 |\n+--------------+\n<strong>Explanation:</strong> \nDaniel and Monica have rated 3 movies (&quot;Avengers&quot;, &quot;Frozen 2&quot; and &quot;Joker&quot;) 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</pre>\n",
"translatedTitle": "电影评分",
"translatedContent": "<p>表:<code>Movies</code></p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| movie_id | int |\n| title | varchar |\n+---------------+---------+\nmovie_id 是这个表的主键(具有唯一值的列)。\ntitle 是电影的名字。\n</pre>\n\n<p>表:<code>Users</code></p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| user_id | int |\n| name | varchar |\n+---------------+---------+\nuser_id 是表的主键(具有唯一值的列)。\n</pre>\n\n<p>表:<code>MovieRating</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>请你编写一个解决方案:</p>\n\n<ul>\n\t<li>查找评论电影数量最多的用户名。如果出现平局,返回字典序较小的用户名。</li>\n\t<li>查找在 <code>February 2020</code><strong> 平均评分最高</strong> 的电影名称。如果出现平局,返回字典序较小的电影名称。</li>\n</ul>\n\n<p><strong>字典序</strong> ,即按字母在字典中出现顺序对字符串排序,字典序较小则意味着排序靠前。</p>\n\n<p>返回结果格式如下例所示。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>\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<strong>输出:</strong>\nResult 表:\n+--------------+\n| results |\n+--------------+\n| Daniel |\n| Frozen 2 |\n+--------------+\n<strong>解释:</strong>\nDaniel 和 Monica 都点评了 3 部电影(\"Avengers\", \"Frozen 2\" 和 \"Joker\" 但是 Daniel 字典序比较小。\nFrozen 2 和 Joker 在 2 月的评分都是 3.5,但是 Frozen 2 的字典序比较小。\n</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -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": "<p>Table: <code>Teacher</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Write a solution to calculate&nbsp;the number of unique subjects each teacher teaches in the university.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The&nbsp;result format is shown in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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+------------+------------+---------+\n<strong>Output:</strong> \n+------------+-----+\n| teacher_id | cnt |\n+------------+-----+\n| 1 | 2 |\n| 2 | 4 |\n+------------+-----+\n<strong>Explanation:</strong> \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</pre>\n",
"translatedTitle": "每位教师所教授的科目种类的数量",
"translatedContent": "<p>表: <code>Teacher</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>查询每位老师在大学里教授的科目种类的数量。</p>\n\n<p data-group=\"1-1\">以 <strong>任意顺序</strong> 返回结果表。</p>\n\n<p>查询结果格式示例如下。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong> \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<strong>输出:</strong> \n+------------+-----+\n| teacher_id | cnt |\n+------------+-----+\n| 1 | 2 |\n| 2 | 4 |\n+------------+-----+\n<strong>解释:</strong> \n教师 1:\n - 他在 3、4 系教科目 2。\n - 他在 3 系教科目 3。\n教师 2:\n - 他在 1 系教科目 1。\n - 他在 1 系教科目 2。\n - 他在 1 系教科目 3。\n - 他在 1 系教科目 4。</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -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": "<p>Table: <code>Users</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Table: <code>Register</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Write a solution to find the percentage of the users registered in each contest rounded to <strong>two decimals</strong>.</p>\n\n<p>Return the result table ordered by <code>percentage</code> in <strong>descending order</strong>. In case of a tie, order it by <code>contest_id</code> in <strong>ascending order</strong>.</p>\n\n<p>The result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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+------------+---------+\n<strong>Output:</strong> \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<strong>Explanation:</strong> \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</pre>\n",
"translatedTitle": "各赛事的用户注册率",
"translatedContent": "<p>用户表:&nbsp;<code>Users</code></p>\n\n<pre>\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| user_id | int |\n| user_name | varchar |\n+-------------+---------+\nuser_id 是该表的主键(具有唯一值的列)。\n该表中的每行包括用户 ID 和用户名。</pre>\n\n<p>&nbsp;</p>\n\n<p>注册表:&nbsp;<code>Register</code></p>\n\n<pre>\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| contest_id | int |\n| user_id | int |\n+-------------+---------+\n(contest_id, user_id) 是该表的主键(具有唯一值的列的组合)。\n该表中的每行包含用户的 ID 和他们注册的赛事。</pre>\n\n<p>&nbsp;</p>\n\n<p>编写解决方案统计出各赛事的用户注册百分率,保留两位小数。</p>\n\n<p>返回的结果表按&nbsp;<code>percentage</code>&nbsp;的&nbsp;<strong>降序&nbsp;</strong>排序,若相同则按&nbsp;<code>contest_id</code>&nbsp;的&nbsp;<strong>升序&nbsp;</strong>排序。</p>\n\n<p>返回结果如下示例所示。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<code><strong>输入:</strong>\nUsers</code> 表:\n+---------+-----------+\n| user_id | user_name |\n+---------+-----------+\n| 6 | Alice |\n| 2 | Bob |\n| 7 | Alex |\n+---------+-----------+\n\n<code>Register</code> 表:\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<strong>输出:</strong>\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<strong>解释:</strong>\n所有用户都注册了 208、209 和 210 赛事,因此这些赛事的注册率为 100% ,我们按 contest_id 的降序排序加入结果表中。\nAlice 和 Alex 注册了 215 赛事,注册率为 ((2/3) * 100) = 66.67%\nBob 注册了 207 赛事,注册率为 ((1/3) * 100) = 33.33%</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -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": "<p>Table: <code>Employee</code></p>\n\n<pre>\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 (&#39;Y&#39;, &#39;N&#39;). If the flag is &#39;Y&#39;, the department is the primary department for the employee. If the flag is &#39;N&#39;, the department is not the primary.\n</pre>\n\n<p>&nbsp;</p>\n\n<p>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 <code>&#39;N&#39;</code>.</p>\n\n<p>Write a solution to report all the employees with their primary department. For employees who belong to one department, report their only department.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The&nbsp;result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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<strong>Output:</strong> \n+-------------+---------------+\n| employee_id | department_id |\n+-------------+---------------+\n| 1 | 1 |\n| 2 | 1 |\n| 3 | 3 |\n| 4 | 3 |\n+-------------+---------------+\n<strong>Explanation:</strong> \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</pre>\n",
"translatedTitle": "员工的直属部门",
"translatedContent": "<p>表:<code>Employee</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>一个员工可以属于多个部门。当一个员工加入<strong>超过一个部门</strong>的时候,他需要决定哪个部门是他的直属部门。请注意,当员工只加入一个部门的时候,那这个部门将默认为他的直属部门,虽然表记录的值为<code>'N'</code>.</p>\n\n<p>请编写解决方案,查出员工所属的直属部门。</p>\n\n<p>返回结果 <strong>没有顺序要求</strong> 。</p>\n\n<p>返回结果格式如下例子所示:</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>\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<strong>输出:</strong>\n+-------------+---------------+\n| employee_id | department_id |\n+-------------+---------------+\n| 1 | 1 |\n| 2 | 1 |\n| 3 | 3 |\n| 4 | 3 |\n+-------------+---------------+\n<strong>解释:</strong>\n- 员工 1 的直属部门是 1\n- 员工 2 的直属部门是 1\n- 员工 3 的直属部门是 3\n- 员工 4 的直属部门是 3</pre>\n\n<p>&nbsp;</p>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -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": "<p>Table: <code>Products</code></p>\n\n<pre>\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.</pre>\n\n<p>&nbsp;</p>\n\n<p>Write a solution to find the prices of all products on <code>2019-08-16</code>. Assume the price of all products before any change is <code>10</code>.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The&nbsp;result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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+------------+-----------+-------------+\n<strong>Output:</strong> \n+------------+-------+\n| product_id | price |\n+------------+-------+\n| 2 | 50 |\n| 1 | 35 |\n| 3 | 10 |\n+------------+-------+\n</pre>\n",
"translatedTitle": "指定日期的产品价格",
"translatedContent": "<p>产品数据表: <code>Products</code></p>\n\n<pre>\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这张表的每一行分别记录了 某产品 在某个日期 更改后 的新价格。</pre>\n\n<p>&nbsp;</p>\n\n<p>编写一个解决方案,找出在&nbsp;<code>2019-08-16</code><strong> </strong>时全部产品的价格,假设所有产品在修改前的价格都是&nbsp;<code>10</code><strong> 。</strong></p>\n\n<p>以 <strong>任意顺序 </strong>返回结果表。</p>\n\n<p>结果格式如下例所示。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>\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<strong>输出:</strong>\n+------------+-------+\n| product_id | price |\n+------------+-------+\n| 2 | 50 |\n| 1 | 35 |\n| 3 | 10 |\n+------------+-------+</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -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": "<p>Table: <code>Sales</code></p>\n\n<pre>\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 <code>Product</code> 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</pre>\n\n<p>&nbsp;</p>\n\n<p>Table: <code>Product</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Write a solution to report the <code>product_name</code>, <code>year</code>, and <code>price</code> for each <code>sale_id</code> in the <code>Sales</code> table.</p>\n\n<p>Return the resulting table in <strong>any order</strong>.</p>\n\n<p>The result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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+------------+--------------+\n<strong>Output:</strong> \n+--------------+-------+-------+\n| product_name | year | price |\n+--------------+-------+-------+\n| Nokia | 2008 | 5000 |\n| Nokia | 2009 | 5000 |\n| Apple | 2011 | 9000 |\n+--------------+-------+-------+\n<strong>Explanation:</strong> \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</pre>\n",
"translatedTitle": "产品销售分析 I",
"translatedContent": "<p>销售表&nbsp;<code>Sales</code></p>\n\n<pre>\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</pre>\n\n<p>产品表&nbsp;<code>Product</code></p>\n\n<pre>\n+--------------+---------+\n| Column Name | Type |\n+--------------+---------+\n| product_id | int |\n| product_name | varchar |\n+--------------+---------+\nproduct_id&nbsp;是表的主键(具有唯一值的列)。\n该表的每一行表示每种产品的产品名称。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>编写解决方案,以获取 <code>Sales</code>&nbsp;表中所有 <code>sale_id</code> 对应的&nbsp;<code>product_name</code> 以及该产品的所有<strong>&nbsp;</strong><code>year</code>&nbsp;和<strong>&nbsp;</strong><code>price</code> 。</p>\n\n<p>返回结果表&nbsp;<strong>无顺序要求</strong> 。</p>\n\n<p>结果格式示例如下。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<code><strong>输入:</strong>\nSales</code> 表:\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<strong>输出:</strong>\n+--------------+-------+-------+\n| product_name | year | price |\n+--------------+-------+-------+\n| Nokia | 2008 | 5000 |\n| Nokia | 2009 | 5000 |\n| Apple | 2011 | 9000 |\n+--------------+-------+-------+\n</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -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": "<p>Table: <code>Sales</code></p>\n\n<pre>\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 <code>Product</code> 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</pre>\n\n<p>&nbsp;</p>\n\n<p>Table: <code>Product</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Write a solution to select&nbsp;the <strong>product id</strong>, <strong>year</strong>, <strong>quantity</strong>, and <strong>price</strong> for the <strong>first year</strong> of every product sold.</p>\n\n<p>Return the resulting table in <strong>any order</strong>.</p>\n\n<p>The&nbsp;result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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+------------+--------------+\n<strong>Output:</strong> \n+------------+------------+----------+-------+\n| product_id | first_year | quantity | price |\n+------------+------------+----------+-------+ \n| 100 | 2008 | 10 | 5000 |\n| 200 | 2011 | 15 | 9000 |\n+------------+------------+----------+-------+\n</pre>\n",
"translatedTitle": "产品销售分析 III",
"translatedContent": "<p>销售表&nbsp;<code>Sales</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>产品表&nbsp;<code>Product</code></p>\n\n<pre>\n+--------------+---------+\n| Column Name | Type |\n+--------------+---------+\n| product_id | int |\n| product_name | varchar |\n+--------------+---------+\nproduct_id 是这张表的主键(具有唯一值的列)。\n这张表的每一行都标识每个产品的 id 和 产品名称。</pre>\n\n<p>&nbsp;</p>\n\n<p>编写解决方案,选出每个售出过的产品&nbsp;<strong>第一年</strong> 销售的 <strong>产品 id</strong>、<strong>年份</strong>、<strong>数量&nbsp;</strong>和 <strong>价格</strong>。</p>\n\n<p>结果表中的条目可以按 <strong>任意顺序</strong> 排列。</p>\n\n<p>结果格式如下例所示:</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>\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<strong>输出:</strong>\n+------------+------------+----------+-------+\n| product_id | first_year | quantity | price |\n+------------+------------+----------+-------+ \n| 100 | 2008 | 10 | 5000 |\n| 200 | 2011 | 15 | 9000 |\n+------------+------------+----------+-------+</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -0,0 +1,98 @@
{
"data": {
"question": {
"questionId": "1161",
"questionFrontendId": "1075",
"categoryTitle": "Database",
"boundTopicId": 8825,
"title": "Project Employees I",
"titleSlug": "project-employees-i",
"content": "<p>Table: <code>Project</code></p>\n\n<pre>\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 <code>Employee</code> table.\nEach row of this table indicates that the employee with employee_id is working on the project with project_id.\n</pre>\n\n<p>&nbsp;</p>\n\n<p>Table: <code>Employee</code></p>\n\n<pre>\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&#39;s guaranteed that experience_years is not NULL.\nEach row of this table contains information about one employee.\n</pre>\n\n<p>&nbsp;</p>\n\n<p>Write an SQL query that reports the <strong>average</strong> experience years of all the employees for each project, <strong>rounded to 2 digits</strong>.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The query result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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+-------------+--------+------------------+\n<strong>Output:</strong> \n+-------------+---------------+\n| project_id | average_years |\n+-------------+---------------+\n| 1 | 2.00 |\n| 2 | 2.50 |\n+-------------+---------------+\n<strong>Explanation:</strong> 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</pre>\n",
"translatedTitle": "项目员工 I",
"translatedContent": "<p>项目表&nbsp;<code>Project</code>&nbsp;</p>\n\n<pre>\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| project_id | int |\n| employee_id | int |\n+-------------+---------+\n主键为 (project_id, employee_id)。\nemployee_id 是员工表 <code>Employee 表的外键。</code>\n</pre>\n\n<p>员工表&nbsp;<code>Employee</code></p>\n\n<pre>\n+------------------+---------+\n| Column Name | Type |\n+------------------+---------+\n| employee_id | int |\n| name | varchar |\n| experience_years | int |\n+------------------+---------+\n主键是 employee_id。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>请写一个 SQL&nbsp;语句,查询每一个项目中员工的&nbsp;<strong>平均&nbsp;</strong>工作年限,<strong>精确到小数点后两位</strong>。</p>\n\n<p>查询结果的格式如下:</p>\n\n<pre>\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</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -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": "<p>Table: <code>Queries</code></p>\n\n<pre>\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 <code>position</code> column has a value from <strong>1</strong> to <strong>500</strong>.\nThe <code>rating</code> column has a value from <strong>1</strong> to <strong>5</strong>. Query with <code>rating</code> less than 3 is a poor query.\n</pre>\n\n<p>&nbsp;</p>\n\n<p>We define query <code>quality</code> as:</p>\n\n<blockquote>\n<p>The average of the ratio between query rating and its position.</p>\n</blockquote>\n\n<p>We also define <code>poor query percentage</code> as:</p>\n\n<blockquote>\n<p>The percentage of all queries with rating less than 3.</p>\n</blockquote>\n\n<p>Write a solution to find each <code>query_name</code>, the <code>quality</code> and <code>poor_query_percentage</code>.</p>\n\n<p>Both <code>quality</code> and <code>poor_query_percentage</code> should be <strong>rounded to 2 decimal places</strong>.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The&nbsp;result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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<strong>Output:</strong> \n+------------+---------+-----------------------+\n| query_name | quality | poor_query_percentage |\n+------------+---------+-----------------------+\n| Dog | 2.50 | 33.33 |\n| Cat | 0.66 | 33.33 |\n+------------+---------+-----------------------+\n<strong>Explanation:</strong> \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</pre>\n",
"translatedTitle": "查询结果的质量和占比",
"translatedContent": "<p><code>Queries</code>&nbsp;表:&nbsp;</p>\n\n<pre>\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| query_name | varchar |\n| result | varchar |\n| position | int |\n| rating | int |\n+-------------+---------+\n此表可能有重复的行。\n此表包含了一些从数据库中收集的查询信息。\n“位置”<code>position</code>)列的值为 <strong>1</strong> 到 <strong>500</strong> 。\n“评分”<code>rating</code>)列的值为 <strong>1</strong> 到 <strong>5</strong> 。评分小于 3 的查询被定义为质量很差的查询。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>将查询结果的质量 <code>quality</code> 定义为:</p>\n\n<blockquote>\n<p>各查询结果的评分与其位置之间比率的平均值。</p>\n</blockquote>\n\n<p>将劣质查询百分比&nbsp;<code>poor_query_percentage</code> 为:</p>\n\n<blockquote>\n<p>评分小于 3 的查询结果占全部查询结果的百分比。</p>\n</blockquote>\n\n<p>编写解决方案,找出每次的&nbsp;<code>query_name</code>&nbsp;、&nbsp;<code>quality</code>&nbsp;和&nbsp;<code>poor_query_percentage</code>。</p>\n\n<p><code>quality</code>&nbsp;和&nbsp;<code>poor_query_percentage</code>&nbsp;都应 <strong>四舍五入到小数点后两位</strong> 。</p>\n\n<p>以 <strong>任意顺序</strong> 返回结果表。</p>\n\n<p>结果格式如下所示:</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>\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<strong>输出:</strong>\n+------------+---------+-----------------------+\n| query_name | quality | poor_query_percentage |\n+------------+---------+-----------------------+\n| Dog | 2.50 | 33.33 |\n| Cat | 0.66 | 33.33 |\n+------------+---------+-----------------------+\n<strong>解释:</strong>\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</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -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": "<p>Table: <code>Employees</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Table: <code>EmployeeUNI</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Write a solution to show the <strong>unique ID </strong>of each user, If a user does not have a unique ID replace just show <code>null</code>.</p>\n\n<p>Return the result table in <strong>any</strong> order.</p>\n\n<p>The result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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+----+-----------+\n<strong>Output:</strong> \n+-----------+----------+\n| unique_id | name |\n+-----------+----------+\n| null | Alice |\n| null | Bob |\n| 2 | Meir |\n| 3 | Winston |\n| 1 | Jonathan |\n+-----------+----------+\n<strong>Explanation:</strong> \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</pre>\n",
"translatedTitle": "使用唯一标识码替换员工ID",
"translatedContent": "<p><code>Employees</code> 表:</p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| id | int |\n| name | varchar |\n+---------------+---------+\n在 SQL 中id 是这张表的主键。\n这张表的每一行分别代表了某公司其中一位员工的名字和 ID 。\n</pre>\n\n<p>&nbsp;</p>\n\n<p><code>EmployeeUNI</code>&nbsp;表:</p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| id | int |\n| unique_id | int |\n+---------------+---------+\n在 SQL 中,(id, unique_id) 是这张表的主键。\n这张表的每一行包含了该公司某位员工的 ID 和他的唯一标识码unique ID。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>展示每位用户的<strong> 唯一标识码unique ID </strong>;如果某位员工没有唯一标识码,使用 null 填充即可。</p>\n\n<p>你可以以<strong> 任意</strong> 顺序返回结果表。</p>\n\n<p>返回结果的格式如下例所示。</p>\n\n<p>&nbsp;</p>\n\n<p><strong class=\"example\">示例 1</strong></p>\n\n<pre>\n<code><strong>输入:</strong>\nEmployees</code> 表:\n+----+----------+\n| id | name |\n+----+----------+\n| 1 | Alice |\n| 7 | Bob |\n| 11 | Meir |\n| 90 | Winston |\n| 3 | Jonathan |\n+----+----------+\n<code>EmployeeUNI</code> 表:\n+----+-----------+\n| id | unique_id |\n+----+-----------+\n| 3 | 1 |\n| 11 | 2 |\n| 90 | 3 |\n+----+-----------+\n<strong>输出:</strong>\n+-----------+----------+\n| unique_id | name |\n+-----------+----------+\n| null | Alice |\n| null | Bob |\n| 2 | Meir |\n| 3 | Winston |\n| 1 | Jonathan |\n+-----------+----------+\n<strong>解释:</strong>\nAlice and Bob 没有唯一标识码, 因此我们使用 null 替代。\nMeir 的唯一标识码是 2 。\nWinston 的唯一标识码是 3 。\nJonathan 唯一标识码是 1 。</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -0,0 +1,98 @@
{
"data": {
"question": {
"questionId": "1452",
"questionFrontendId": "1321",
"categoryTitle": "Database",
"boundTopicId": 74822,
"title": "Restaurant Growth",
"titleSlug": "restaurant-growth",
"content": "<p>Table: <code>Customer</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>You are the restaurant owner and you want to analyze a possible expansion (there will be at least one customer every day).</p>\n\n<p>Compute the moving average of how much the customer paid in a seven days window (i.e., current day + 6 days before). <code>average_amount</code> should be <strong>rounded to two decimal places</strong>.</p>\n\n<p>Return the result table ordered by <code>visited_on</code> <strong>in ascending order</strong>.</p>\n\n<p>The result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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+-------------+--------------+--------------+-------------+\n<strong>Output:</strong> \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<strong>Explanation:</strong> \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</pre>\n",
"translatedTitle": "餐馆营业额变化增长",
"translatedContent": "<p>表: <code>Customer</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>你是餐馆的老板,现在你想分析一下可能的营业额变化增长(每天至少有一位顾客)。</p>\n\n<p>计算以 7 天(某日期 + 该日期前的 6 天)为一个时间段的顾客消费平均值。<code>average_amount</code>&nbsp;要 <strong>保留两位小数。</strong></p>\n\n<p>结果按 <code>visited_on</code>&nbsp;<strong>升序排序</strong>。</p>\n\n<p>返回结果格式的例子如下。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>\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<strong>输出:</strong>\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<strong>解释:</strong>\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</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -0,0 +1,109 @@
{
"data": {
"question": {
"questionId": "1415",
"questionFrontendId": "1280",
"categoryTitle": "Database",
"boundTopicId": 51351,
"title": "Students and Examinations",
"titleSlug": "students-and-examinations",
"content": "<p>Table: <code>Students</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Table: <code>Subjects</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Table: <code>Examinations</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Write a solution to find the number of times each student attended each exam.</p>\n\n<p>Return the result table ordered by <code>student_id</code> and <code>subject_name</code>.</p>\n\n<p>The result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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<strong>Output:</strong> \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<strong>Explanation:</strong> \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</pre>\n",
"translatedTitle": "学生们参加各科测试的次数",
"translatedContent": "<p>学生表: <code>Students</code></p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| student_id | int |\n| student_name | varchar |\n+---------------+---------+\n在 SQL 中,主键为 student_id学生ID。\n该表内的每一行都记录有学校一名学生的信息。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>科目表: <code>Subjects</code></p>\n\n<pre>\n+--------------+---------+\n| Column Name | Type |\n+--------------+---------+\n| subject_name | varchar |\n+--------------+---------+\n在 SQL 中,主键为 subject_name科目名称。\n每一行记录学校的一门科目名称。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>考试表: <code>Examinations</code></p>\n\n<pre>\n+--------------+---------+\n| Column Name | Type |\n+--------------+---------+\n| student_id | int |\n| subject_name | varchar |\n+--------------+---------+\n这个表可能包含重复数据换句话说在 SQL 中,这个表没有主键)。\n学生表里的一个学生修读科目表里的每一门科目。\n这张考试表的每一行记录就表示学生表里的某个学生参加了一次科目表里某门科目的测试。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>查询出每个学生参加每一门科目测试的次数,结果按 <code>student_id</code> 和 <code>subject_name</code> 排序。</p>\n\n<p>查询结构格式如下所示。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1</strong></p>\n\n<pre>\n<strong>输入:</strong>\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<strong>输出:</strong>\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<strong>解释:</strong>\n结果表需包含所有学生和所有科目即便测试次数为0\nAlice 参加了 3 次数学测试, 2 次物理测试,以及 1 次编程测试;\nBob 参加了 1 次数学测试, 1 次编程测试,没有参加物理测试;\nAlex 啥测试都没参加;\nJohn 参加了数学、物理、编程测试各 1 次。\n</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -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": "<p>Table: <code>Employees</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>For this problem, we will consider a <strong>manager</strong> an employee who has at least 1 other employee reporting to them.</p>\n\n<p>Write a solution to report the ids and the names of all <strong>managers</strong>, the number of employees who report <strong>directly</strong> to them, and the average age of the reports rounded to the nearest integer.</p>\n\n<p>Return the result table ordered by <code>employee_id</code>.</p>\n\n<p>The&nbsp;result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \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+-------------+---------+------------+-----+\n<strong>Output:</strong> \n+-------------+-------+---------------+-------------+\n| employee_id | name | reports_count | average_age |\n+-------------+-------+---------------+-------------+\n| 9 | Hercy | 2 | 39 |\n+-------------+-------+---------------+-------------+\n<strong>Explanation:</strong> 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</pre>\n",
"translatedTitle": "每位经理的下属员工数量",
"translatedContent": "<p>Table: <code>Employees</code></p>\n\n<pre>+-------------+----------+\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</pre>\n\n<p> </p>\n\n<p>对于此问题,我们将至少有一个其他员工需要向他汇报的员工,视为一个经理。</p>\n\n<p>编写SQL查询需要听取汇报的所有经理的ID、名称、直接向该经理汇报的员工人数以及这些员工的平均年龄其中该平均年龄需要四舍五入到最接近的整数。</p>\n\n<p>返回的结果集需要按照 <code>employee_id </code>进行排序。</p>\n\n<p>查询结果的格式如下:</p>\n\n<p> </p>\n\n<pre>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</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -0,0 +1,89 @@
{
"data": {
"question": {
"questionId": "610",
"questionFrontendId": "610",
"categoryTitle": "Database",
"boundTopicId": 2636,
"title": "Triangle Judgement",
"titleSlug": "triangle-judgement",
"content": "<p>Table: <code>Triangle</code></p>\n\n<pre>\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</pre>\n\n<p>&nbsp;</p>\n\n<p>Report for every three line segments whether they can form a triangle.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The&nbsp;result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nTriangle table:\n+----+----+----+\n| x | y | z |\n+----+----+----+\n| 13 | 15 | 30 |\n| 10 | 20 | 15 |\n+----+----+----+\n<strong>Output:</strong> \n+----+----+----+----------+\n| x | y | z | triangle |\n+----+----+----+----------+\n| 13 | 15 | 30 | No |\n| 10 | 20 | 15 | Yes |\n+----+----+----+----------+\n</pre>\n",
"translatedTitle": "判断三角形",
"translatedContent": "<p>表:&nbsp;<code>Triangle</code></p>\n\n<pre>\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| x | int |\n| y | int |\n| z | int |\n+-------------+------+\n在 SQL 中,(x, y, z)是该表的主键列。\n该表的每一行包含三个线段的长度。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>对每三个线段报告它们是否可以形成一个三角形。</p>\n\n<p>以&nbsp;<strong>任意顺序&nbsp;</strong>返回结果表。</p>\n\n<p>查询结果格式如下所示。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong> \nTriangle 表:\n+----+----+----+\n| x | y | z |\n+----+----+----+\n| 13 | 15 | 30 |\n| 10 | 20 | 15 |\n+----+----+----+\n<strong>输出:</strong> \n+----+----+----+----------+\n| x | y | z | triangle |\n+----+----+----+----------+\n| 13 | 15 | 30 | No |\n| 10 | 20 | 15 | Yes |\n+----+----+----+----------+</pre>\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\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}

View File

@ -0,0 +1,63 @@
<p><code>Insurance</code> 表:</p>
<div class="original__bRMd">
<div>
<pre>
+-------------+-------+
| 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 不为空。</pre>
<p>&nbsp;</p>
<p>编写解决方案报告 2016 年 (<code>tiv_2016</code>) 所有满足下述条件的投保人的投保金额之和:</p>
<ul>
<li>他在 2015 年的投保额&nbsp;(<code>tiv_2015</code>) 至少跟一个其他投保人在 2015 年的投保额相同。</li>
<li>他所在的城市必须与其他投保人都不同(也就是说&nbsp;(<code>lat, lon</code>) 不能跟其他任何一个投保人完全相同)。</li>
</ul>
<p><code>tiv_2016</code> 四舍五入的 <strong>两位小数</strong></p>
<p>查询结果格式如下例所示。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<strong>输入:</strong>
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 |
+-----+----------+----------+-----+-----+
<strong>输出:</strong>
+----------+
| tiv_2016 |
+----------+
| 45.00 |
+----------+
<strong>解释:
</strong>表中的第一条记录和最后一条记录都满足两个条件。
tiv_2015 值为 10 与第三条和第四条记录相同,且其位置是唯一的。
第二条记录不符合任何一个条件。其 tiv_2015 与其他投保人不同,并且位置与第三条记录相同,这也导致了第三条记录不符合题目要求。
因此,结果是第一条记录和最后一条记录的 tiv_2016 之和,即 45 。</pre>
</div>
</div>

View File

@ -0,0 +1,32 @@
<p>逆序对的定义如下:对于数组 <code>nums</code> 的第 <code>i</code> 个和第 <code>j</code> 个元素,如果满足 <code>0 &lt;= i &lt; j &lt; nums.length</code>&nbsp;<code>nums[i] &gt; nums[j]</code>,则其为一个逆序对;否则不是。</p>
<p>给你两个整数&nbsp;<code>n</code>&nbsp;&nbsp;<code>k</code>,找出所有包含从&nbsp;<code>1</code>&nbsp;&nbsp;<code>n</code>&nbsp;的数字,且恰好拥有&nbsp;<code>k</code>&nbsp;<strong>逆序对</strong> 的不同的数组的个数。由于答案可能很大,只需要返回对 <code>10<sup>9</sup>&nbsp;+ 7</code> 取余的结果。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>n = 3, k = 0
<strong>输出:</strong>1
<strong>解释:</strong>
只有数组 [1,2,3] 包含了从1到3的整数并且正好拥有 0 个逆序对。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>n = 3, k = 1
<strong>输出:</strong>2
<strong>解释:</strong>
数组 [1,3,2] 和 [2,1,3] 都有 1 个逆序对。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= n &lt;= 1000</code></li>
<li><code>0 &lt;= k &lt;= 1000</code></li>
</ul>

View File

@ -0,0 +1,53 @@
<p>表: <code>Employees</code></p>
<pre>
+-------------+----------+
| Column Name | Type |
+-------------+----------+
| employee_id | int |
| name | varchar |
| manager_id | int |
| salary | int |
+-------------+----------+
在 SQL 中employee_id 是这个表的主键。
这个表包含了员工他们的薪水和上级经理的id。
有一些员工没有上级经理(其 manager_id 是空值)。
</pre>
<p>&nbsp;</p>
<p>查找这些员工的id他们的薪水严格少于<code>$30000</code>&nbsp;并且他们的上级经理已离职。当一个经理离开公司时,他们的信息需要从员工表中删除掉,但是表中的员工的<code>manager_id</code> &nbsp;这一列还是设置的离职经理的id&nbsp;</p>
<p>返回的结果按照<code>employee_id&nbsp;</code>从小到大排序。</p>
<p>查询结果如下所示:</p>
<p>&nbsp;</p>
<p><strong>示例:</strong></p>
<pre>
<strong>输入:</strong>
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 |
+-------------+-----------+------------+--------+
<strong>输出:</strong>
+-------------+
| employee_id |
+-------------+
| 11 |
+-------------+
<strong>解释:</strong>
薪水少于 30000 美元的员工有 1 号(Kalel) 和 11号 (Joziah)。
Kalel 的上级经理是 11 号员工,他还在公司上班(他是 Joziah )。
Joziah 的上级经理是 6 号员工,他已经离职,因为员工表里面已经没有 6 号员工的信息了,它被删除了。
</pre>

View File

@ -0,0 +1,33 @@
<p>给你&nbsp;<code>n</code>&nbsp;个二维平面上的点 <code>points</code> ,其中&nbsp;<code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>&nbsp;,请你返回两点之间内部不包含任何点的&nbsp;<strong>最宽垂直区域</strong> 的宽度。</p>
<p><strong>垂直区域</strong> 的定义是固定宽度,而 y 轴上无限延伸的一块区域(也就是高度为无穷大)。 <strong>最宽垂直区域</strong> 为宽度最大的一个垂直区域。</p>
<p>请注意,垂直区域&nbsp;<strong>边上</strong>&nbsp;的点&nbsp;<strong>不在</strong>&nbsp;区域内。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<img alt="" src="https://assets.leetcode-cn.com/aliyun-lc-upload/uploads/2020/10/31/points3.png" style="width: 276px; height: 371px;" />
<pre>
<b>输入:</b>points = [[8,7],[9,9],[7,4],[9,7]]
<b>输出:</b>1
<b>解释:</b>红色区域和蓝色区域都是最优区域。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<b>输入:</b>points = [[3,1],[9,0],[1,0],[1,4],[5,3],[8,8]]
<b>输出:</b>3
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == points.length</code></li>
<li><code>2 &lt;= n &lt;= 10<sup>5</sup></code></li>
<li><code>points[i].length == 2</code></li>
<li><code>0 &lt;= x<sub>i</sub>, y<sub>i</sub>&nbsp;&lt;= 10<sup>9</sup></code></li>
</ul>

View File

@ -0,0 +1,27 @@
给你一个整数数组 <code>nums</code> 和一个整数 <code>k</code> ,请你返回子数组内所有元素的乘积严格小于<em> </em><code>k</code> 的连续子数组的数目。
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = [10,5,2,6], k = 100
<strong>输出:</strong>8
<strong>解释:</strong>8 个乘积小于 100 的子数组分别为:[10]、[5]、[2],、[6]、[10,5]、[5,2]、[2,6]、[5,2,6]。
需要注意的是 [10,5,2] 并不是乘积小于 100 的子数组。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [1,2,3], k = 0
<strong>输出:</strong>0</pre>
<p>&nbsp;</p>
<p><strong>提示:&nbsp;</strong></p>
<ul>
<li><code>1 &lt;= nums.length &lt;= 3 * 10<sup>4</sup></code></li>
<li><code>1 &lt;= nums[i] &lt;= 1000</code></li>
<li><code>0 &lt;= k &lt;= 10<sup>6</sup></code></li>
</ul>

View File

@ -0,0 +1,66 @@
<p><code>Customer</code>&nbsp;表:</p>
<pre>
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| customer_id | int |
| product_key | int |
+-------------+---------+
该表可能包含重复的行。
customer_id 不为 NULL。
product_key 是 Product 表的外键(reference 列)。
</pre>
<p><code>Product</code>&nbsp;表:</p>
<pre>
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| product_key | int |
+-------------+---------+
product_key 是这张表的主键(具有唯一值的列)。
</pre>
<p>&nbsp;</p>
<p>编写解决方案,报告&nbsp;<code>Customer</code> 表中购买了 <code>Product</code> 表中所有产品的客户的 id。</p>
<p>返回结果表 <strong>无顺序要求</strong></p>
<p>返回结果格式如下所示。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>
Customer 表:
+-------------+-------------+
| customer_id | product_key |
+-------------+-------------+
| 1 | 5 |
| 2 | 6 |
| 3 | 5 |
| 3 | 6 |
| 1 | 6 |
+-------------+-------------+
Product 表:
+-------------+
| product_key |
+-------------+
| 5 |
| 6 |
+-------------+
<strong>输出:</strong>
+-------------+
| customer_id |
+-------------+
| 1 |
| 3 |
+-------------+
<strong>解释:</strong>
购买了所有产品5 和 6的客户的 id 是 1 和 3 。
</pre>

View File

@ -0,0 +1,36 @@
<p>数组 <code>prices</code> 记录了某芯片近期的交易价格,其中 <code>prices[i]</code> 表示的 <code>i</code> 天该芯片的价格。你只能选择 <strong>某一天</strong> 买入芯片,并选择在 <strong>未来的某一个不同的日子</strong> 卖出该芯片。请设计一个算法计算并返回你从这笔交易中能获取的最大利润。</p>
<p>如果你不能获取任何利润,返回 0。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>prices = [3, 6, 2, 9, 8, 5]
<strong>输出:</strong>7
<strong>解释:</strong>在第 3 天(芯片价格 = 2买入在第 4 天(芯片价格 = 9卖出最大利润 = 9 - 2 = 7。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>prices = [8, 12, 15, 7, 3, 10]
<strong>输出:</strong>7
<strong>解释:</strong>在第 5 天(芯片价格 = 3买入在第 6 天(芯片价格 = 10卖出最大利润 = 10 - 3 = 7。
</pre>
<p>&nbsp;</p>
<p><b>提示:</b></p>
<ul>
<li><code>0 &lt;= prices.length &lt;= 10^5</code></li>
<li><code>0 &lt;= prices[i] &lt;= 10^4</code></li>
</ul>
<p>&nbsp;</p>
<p><strong>注意:</strong>本题与主站 121 题相同:<a href="https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/">https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock/</a></p>
<p>&nbsp;</p>

View File

@ -0,0 +1,49 @@
<p>序列化是将一个数据结构或者对象转换为连续的比特位的操作,进而可以将转换后的数据存储在一个文件或者内存中,同时也可以通过网络传输到另一个计算机环境,采取相反方式重构得到原数据。</p>
<p>请设计一个算法来实现二叉树的序列化与反序列化。这里不限定你的序列 / 反序列化算法执行逻辑,只需要保证一个二叉树可以被序列化为一个字符串并且将这个字符串反序列化为原始的树结构。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2020/09/15/serdeser.jpg" style="width: 442px; height: 324px;" /></p>
<pre>
<strong>输入:</strong>root = [1,2,3,null,null,4,5]
<strong>输出:</strong>[1,2,3,null,null,4,5]
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>root = []
<strong>输出:</strong>[]
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>root = [1]
<strong>输出:</strong>[1]
</pre>
<p><strong>示例 4</strong></p>
<pre>
<strong>输入:</strong>root = [1,2]
<strong>输出:</strong>[1,2]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li>输入输出格式与 LeetCode 目前使用的方式一致,详情请参阅&nbsp;<a href="/faq/#binary-tree">LeetCode 序列化二叉树的格式</a>。你并非必须采取这种方式,也可以采用其他的方法解决这个问题。</li>
<li>树中结点数在范围 <code>[0, 10<sup>4</sup>]</code></li>
<li><code>-1000 &lt;= Node.val &lt;= 1000</code></li>
</ul>
<p>&nbsp;</p>
<p><meta charset="UTF-8" />注意:本题与主站 297&nbsp;题相同:<a href="https://leetcode-cn.com/problems/serialize-and-deserialize-binary-tree/">https://leetcode-cn.com/problems/serialize-and-deserialize-binary-tree/</a>&nbsp;</p>

View File

@ -0,0 +1,17 @@
<p>在股票交易中,如果前一天的股价高于后一天的股价,则可以认为存在一个「交易逆序对」。请设计一个程序,输入一段时间内的股票交易记录 <code>record</code>,返回其中存在的「交易逆序对」总数。</p>
<p>&nbsp;</p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong>record = [9, 7, 5, 4, 6]
<strong>输出:</strong>8
<strong>解释:</strong>交易中的逆序对为 (9, 7), (9, 5), (9, 4), (9, 6), (7, 5), (7, 4), (7, 6), (5, 4)。
</pre>
<p>&nbsp;</p>
<p><strong>限制:</strong></p>
<p><code>0 &lt;= record.length &lt;= 50000</code></p>

View File

@ -0,0 +1,70 @@
<p>销售表&nbsp;<code>Sales</code></p>
<pre>
+-------------+-------+
| 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 表示每单位价格。
</pre>
<p>产品表&nbsp;<code>Product</code></p>
<pre>
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| product_id | int |
| product_name | varchar |
+--------------+---------+
product_id&nbsp;是表的主键(具有唯一值的列)。
该表的每一行表示每种产品的产品名称。
</pre>
<p>&nbsp;</p>
<p>编写解决方案,以获取 <code>Sales</code>&nbsp;表中所有 <code>sale_id</code> 对应的&nbsp;<code>product_name</code> 以及该产品的所有<strong>&nbsp;</strong><code>year</code>&nbsp;<strong>&nbsp;</strong><code>price</code></p>
<p>返回结果表&nbsp;<strong>无顺序要求</strong></p>
<p>结果格式示例如下。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<code><strong>输入:</strong>
Sales</code> 表:
+---------+------------+------+----------+-------+
| 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 |
+------------+--------------+
<strong>输出:</strong>
+--------------+-------+-------+
| product_name | year | price |
+--------------+-------+-------+
| Nokia | 2008 | 5000 |
| Nokia | 2009 | 5000 |
| Apple | 2011 | 9000 |
+--------------+-------+-------+
</pre>

View File

@ -0,0 +1,69 @@
<p>销售表&nbsp;<code>Sales</code></p>
<pre>
+-------------+-------+
| Column Name | Type |
+-------------+-------+
| sale_id | int |
| product_id | int |
| year | int |
| quantity | int |
| price | int |
+-------------+-------+
(sale_id, year) 是这张表的主键(具有唯一值的列的组合)。
product_id 是产品表的外键reference 列)。
这张表的每一行都表示:编号 product_id 的产品在某一年的销售额。
请注意,价格是按每单位计的。
</pre>
<p>&nbsp;</p>
<p>产品表&nbsp;<code>Product</code></p>
<pre>
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| product_id | int |
| product_name | varchar |
+--------------+---------+
product_id 是这张表的主键(具有唯一值的列)。
这张表的每一行都标识:每个产品的 id 和 产品名称。</pre>
<p>&nbsp;</p>
<p>编写解决方案,选出每个售出过的产品&nbsp;<strong>第一年</strong> 销售的 <strong>产品 id</strong><strong>年份</strong><strong>数量&nbsp;</strong><strong>价格</strong></p>
<p>结果表中的条目可以按 <strong>任意顺序</strong> 排列。</p>
<p>结果格式如下例所示:</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>
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 |
+------------+--------------+
<strong>输出:</strong>
+------------+------------+----------+-------+
| product_id | first_year | quantity | price |
+------------+------------+----------+-------+
| 100 | 2008 | 10 | 5000 |
| 200 | 2011 | 15 | 9000 |
+------------+------------+----------+-------+</pre>

View File

@ -0,0 +1,31 @@
<p>编写一个解决方案,基于名为&nbsp;&nbsp;<code>student_data</code>&nbsp;的二维列表&nbsp;<b>创建 </b>一个 DataFrame 。这个二维列表包含一些学生的 ID 和年龄信息。</p>
<p>DataFrame 应该有两列,&nbsp;<code>student_id</code>&nbsp;&nbsp;<code>age</code>,并且与原始二维列表的顺序相同。</p>
<p>返回结果格式如下示例所示。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<strong>输入:
</strong>student_data:<strong>
</strong><code>[
[1, 15],
[2, 11],
[3, 11],
[4, 20]
]</code>
<b>输出:</b>
+------------+-----+
| student_id | age |
+------------+-----+
| 1 | 15 |
| 2 | 11 |
| 3 | 11 |
| 4 | 20 |
+------------+-----+
<b>解释:</b>
基于 student_data 创建了一个 DataFrame包含 student_id 和 age 两列。
</pre>

View File

@ -0,0 +1,75 @@
<p><code>Employees</code> 表:</p>
<pre>
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| id | int |
| name | varchar |
+---------------+---------+
在 SQL 中id 是这张表的主键。
这张表的每一行分别代表了某公司其中一位员工的名字和 ID 。
</pre>
<p>&nbsp;</p>
<p><code>EmployeeUNI</code>&nbsp;表:</p>
<pre>
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| id | int |
| unique_id | int |
+---------------+---------+
在 SQL 中,(id, unique_id) 是这张表的主键。
这张表的每一行包含了该公司某位员工的 ID 和他的唯一标识码unique ID
</pre>
<p>&nbsp;</p>
<p>展示每位用户的<strong> 唯一标识码unique ID </strong>;如果某位员工没有唯一标识码,使用 null 填充即可。</p>
<p>你可以以<strong> 任意</strong> 顺序返回结果表。</p>
<p>返回结果的格式如下例所示。</p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<code><strong>输入:</strong>
Employees</code> 表:
+----+----------+
| id | name |
+----+----------+
| 1 | Alice |
| 7 | Bob |
| 11 | Meir |
| 90 | Winston |
| 3 | Jonathan |
+----+----------+
<code>EmployeeUNI</code> 表:
+----+-----------+
| id | unique_id |
+----+-----------+
| 3 | 1 |
| 11 | 2 |
| 90 | 3 |
+----+-----------+
<strong>输出:</strong>
+-----------+----------+
| unique_id | name |
+-----------+----------+
| null | Alice |
| null | Bob |
| 2 | Meir |
| 3 | Winston |
| 1 | Jonathan |
+-----------+----------+
<strong>解释:</strong>
Alice and Bob 没有唯一标识码, 因此我们使用 null 替代。
Meir 的唯一标识码是 2 。
Winston 的唯一标识码是 3 。
Jonathan 唯一标识码是 1 。</pre>

View File

@ -0,0 +1,42 @@
<pre>
DataFrame <code>employees</code>
+-------------+--------+
| Column Name | Type |
+-------------+--------+
| name | object |
| salary | int |
+-------------+--------+
</pre>
<p>一家公司决定增加员工的薪水。</p>
<p>编写一个解决方案将每个员工的薪水乘以2来 <strong>修改</strong>&nbsp;<code>salary</code>&nbsp;列。</p>
<p>返回结果格式如下示例所示。</p>
<p>&nbsp;</p>
<p><b>示例 1:</b></p>
<pre>
<strong>输入:
</strong>DataFrame employees
+---------+--------+
| name | salary |
+---------+--------+
| Jack | 19666 |
| Piper | 74754 |
| Mia | 62509 |
| Ulysses | 54866 |
+---------+--------+
<strong>输出:
</strong>+---------+--------+
| name | salary |
+---------+--------+
| Jack | 39332 |
| Piper | 149508 |
| Mia | 125018 |
| Ulysses | 109732 |
+---------+--------+
<strong>解释:
</strong>每个人的薪水都被加倍。</pre>

View File

@ -0,0 +1,85 @@
<p>表: <code>Products</code></p>
<pre>
+------------------+---------+
| Column Name | Type |
+------------------+---------+
| product_id | int |
| product_name | varchar |
| product_category | varchar |
+------------------+---------+
product_id 是该表主键(具有唯一值的列)。
该表包含该公司产品的数据。
</pre>
<p>&nbsp;</p>
<p>表: <code>Orders</code></p>
<pre>
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| product_id | int |
| order_date | date |
| unit | int |
+---------------+---------+
该表可能包含重复行。
product_id 是表单 Products 的外键reference 列)。
unit 是在日期 order_date 内下单产品的数目。
</pre>
<p>&nbsp;</p>
<p>写一个解决方案,要求获取在 2020 年 2 月份下单的数量不少于 100 的产品的名字和数目。</p>
<p>返回结果表单的 <strong>顺序无要求 </strong></p>
<p>查询结果的格式如下。</p>
<p>&nbsp;</p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong>
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 |
+--------------+--------------+----------+
<strong>输出:</strong>
+--------------------+---------+
| product_name | unit |
+--------------------+---------+
| Leetcode Solutions | 130 |
| Leetcode Kit | 100 |
+--------------------+---------+
<strong>解释:</strong>
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 。</pre>

View File

@ -0,0 +1,46 @@
<pre>
DataFrame <code>employees</code>
+-------------+--------+
| Column Name | Type. |
+-------------+--------+
| name | object |
| salary | int. |
+-------------+--------+
</pre>
<p>一家公司计划为员工提供奖金。</p>
<p>编写一个解决方案,创建一个名为&nbsp;<code>bonus</code>&nbsp;的新列,其中包含&nbsp;<code>salary</code>&nbsp;值的&nbsp;<strong>两倍</strong></p>
<p>返回结果格式如下示例所示。</p>
<p>&nbsp;</p>
<p><b>示例 1:</b></p>
<pre>
<b>输入:</b>
DataFrame employees
+---------+--------+
| name | salary |
+---------+--------+
| Piper | 4548 |
| Grace | 28150 |
| Georgia | 1103 |
| Willow | 6593 |
| Finn | 74576 |
| Thomas | 24433 |
+---------+--------+
<b>输出:</b>
+---------+--------+--------+
| name | salary | bonus |
+---------+--------+--------+
| Piper | 4548 | 9096 |
| Grace | 28150 | 56300 |
| Georgia | 1103 | 2206 |
| Willow | 593 | 13186 |
| Finn | 74576 | 149152 |
| Thomas | 24433 | 48866 |
+---------+--------+--------+
<b>解释:</b>
通过将 salary 列中的值加倍创建了一个新的 bonus 列。</pre>

View File

@ -0,0 +1,41 @@
<pre>
DataFrame students
+-------------+--------+
| Column Name | Type |
+-------------+--------+
| student_id | int |
| name | object |
| age | int |
+-------------+--------+
</pre>
<p><code>name</code> 列里有一些具有缺失值的行。</p>
<p>编写一个解决方案,删除具有缺失值的行。</p>
<p>返回结果格式如下示例所示。</p>
<p>&nbsp;</p>
<p><b>示例 1:</b></p>
<pre>
<strong>输入:
</strong>+------------+---------+-----+
| student_id | name | age |
+------------+---------+-----+
| 32 | Piper | 5 |
| 217 | None | 19 |
| 779 | Georgia | 20 |
| 849 | Willow | 14 |
+------------+---------+-----+
<strong>输出:
</strong>+------------+---------+-----+
| student_id | name | age |
+------------+---------+-----+
| 32 | Piper | 5 |
| 779 | Georgia | 20 |
| 849 | Willow | 14 |
+------------+---------+-----+
<b>解释:
</b>学号为 217 的学生所在行在 name 列中有空值,因此这一行将被删除。</pre>

View File

@ -0,0 +1,46 @@
<pre>
DataFrame customers
+-------------+--------+
| Column Name | Type |
+-------------+--------+
| customer_id | int |
| name | object |
| email | object |
+-------------+--------+
</pre>
<p>在 DataFrame 中基于&nbsp;<code>email</code>&nbsp;列存在一些重复行。</p>
<p>编写一个解决方案,删除这些重复行,仅保留第一次出现的行。</p>
<p>返回结果格式如下例所示。</p>
<p>&nbsp;</p>
<p><strong>示例 1:</strong></p>
<pre>
<b>输入:</b>
+-------------+---------+---------------------+
| 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 |
+-------------+---------+---------------------+
<b>输出:</b>
+-------------+---------+---------------------+
| 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 |
+-------------+---------+---------------------+
<b>解释:</b>
Alice (customer_id = 4) 和 Finn (customer_id = 5) 都使用 john@example.com因此只保留该邮箱地址的第一次出现。
</pre>

View File

@ -0,0 +1,42 @@
<p>表:&nbsp;<code>Triangle</code></p>
<pre>
+-------------+------+
| Column Name | Type |
+-------------+------+
| x | int |
| y | int |
| z | int |
+-------------+------+
在 SQL 中,(x, y, z)是该表的主键列。
该表的每一行包含三个线段的长度。
</pre>
<p>&nbsp;</p>
<p>对每三个线段报告它们是否可以形成一个三角形。</p>
<p>&nbsp;<strong>任意顺序&nbsp;</strong>返回结果表。</p>
<p>查询结果格式如下所示。</p>
<p>&nbsp;</p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong>
Triangle 表:
+----+----+----+
| x | y | z |
+----+----+----+
| 13 | 15 | 30 |
| 10 | 20 | 15 |
+----+----+----+
<strong>输出:</strong>
+----+----+----+----------+
| x | y | z | triangle |
+----+----+----+----------+
| 13 | 15 | 30 | No |
| 10 | 20 | 15 | Yes |
+----+----+----+----------+</pre>

View File

@ -0,0 +1,31 @@
<p>请设计一个函数判断一棵二叉树是否 <strong>轴对称</strong></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://pic.leetcode.cn/1694689008-JaaRdV-%E8%BD%B4%E5%AF%B9%E7%A7%B0%E4%BA%8C%E5%8F%89%E6%A0%911.png" /></p>
<pre>
<strong>输入:</strong>root = [6,7,7,8,9,9,8]
<strong>输出:</strong>true
<strong>解释:</strong>从图中可看出树是轴对称的。</pre>
<p><strong>示例 2</strong></p>
<p><img alt="" src="https://pic.leetcode.cn/1694689054-vENzHe-%E8%BD%B4%E5%AF%B9%E7%A7%B0%E4%BA%8C%E5%8F%89%E6%A0%912.png" /></p>
<pre>
<strong>输入:</strong>root = [1,2,2,null,3,null,3]
<strong>输出:</strong>false
<strong>解释:</strong>从图中可看出最后一层的节点不对称。</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<p><code>0 &lt;= 节点个数 &lt;= 1000</code></p>
<p>注意:本题与主站 101 题相同:<a href="https://leetcode-cn.com/problems/symmetric-tree/">https://leetcode-cn.com/problems/symmetric-tree/</a></p>
<p>&nbsp;</p>

View File

@ -0,0 +1,31 @@
<p>输入一棵二叉树的根节点判断该树是不是平衡二叉树。如果某二叉树中任意节点的左右子树的深度相差不超过1那么它就是一棵平衡二叉树。</p>
<p>&nbsp;</p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong>root = [3,9,20,null,null,15,7]
<strong>输出:</strong>true
<strong>解释:</strong>如下图
</pre>
<p><img alt="" src="https://pic.leetcode.cn/1695102431-vbmWJn-image.png" style="height: 281px; width: 500px;" /><br />
<br />
<strong>示例 2:</strong></p>
<pre>
输入root = [1,2,2,3,3,null,null,4,4]
输出false
解释:如下图
</pre>
<img alt="" src="https://pic.leetcode.cn/1695102434-WlaxCo-image.png" style="height: 281px; width: 500px;" />
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>0 &lt;= 树的结点个数 &lt;= 10000</code></li>
</ul>
<p>注意:本题与主站 110&nbsp;题相同:<a href="https://leetcode-cn.com/problems/balanced-binary-tree/">https://leetcode-cn.com/problems/balanced-binary-tree/</a></p>

View File

@ -0,0 +1,29 @@
<p>计算机安全专家正在开发一款高度安全的加密通信软件,需要在进行数据传输时对数据进行加密和解密操作。假定 <code>dataA</code><code>dataB</code> 分别为随机抽样的两次通信的数据量:</p>
<ul>
<li>正数为发送量</li>
<li>负数为接受量</li>
<li>0 为数据遗失</li>
</ul>
<p>请不使用四则运算符的情况下实现一个函数计算两次通信的数据量之和(三种情况均需被统计),以确保在数据传输过程中的高安全性和保密性。</p>
<p>&nbsp;</p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong>dataA = 5, dataB = -1
<strong>输出:</strong>4
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>dataA</code>&nbsp;<code>dataB</code>&nbsp;均可能是负数或 0</li>
<li>结果不会溢出 32 位整数</li>
</ul>
<p>&nbsp;</p>

View File

@ -0,0 +1,34 @@
<p>某公司门禁密码使用动态口令技术。初始密码为字符串 <code>password</code>,密码更新均遵循以下步骤:</p>
<ul>
<li>设定一个正整数目标值 <code>target</code></li>
<li><code>password</code><code>target</code> 个字符按原顺序移动至字符串末尾</li>
</ul>
<p>请返回更新后的密码字符串。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong> password = "s3cur1tyC0d3", target = 4
<strong>输出:</strong> "r1tyC0d3s3cu"
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong> password = "lrloseumgh", target = 6
<strong>输出:&nbsp;</strong>"umghlrlose"
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= target&nbsp;&lt; password.length &lt;= 10000</code></li>
</ul>
<p>&nbsp;</p>

View File

@ -0,0 +1,56 @@
<p>配送表: <code>Delivery</code></p>
<pre>
+-----------------------------+---------+
| Column Name | Type |
+-----------------------------+---------+
| delivery_id | int |
| customer_id | int |
| order_date | date |
| customer_pref_delivery_date | date |
+-----------------------------+---------+
delivery_id 是该表中具有唯一值的列。
该表保存着顾客的食物配送信息,顾客在某个日期下了订单,并指定了一个期望的配送日期(和下单日期相同或者在那之后)。
</pre>
<p>&nbsp;</p>
<p>如果顾客期望的配送日期和下单日期相同,则该订单称为 「<strong>即时订单</strong>」,否则称为「<strong>计划订单</strong>」。</p>
<p><strong>首次订单</strong>」是顾客最早创建的订单。我们保证一个顾客只会有一个「首次订单」。</p>
<p>编写解决方案以获取即时订单在所有用户的首次订单中的比例。<strong>保留两位小数。</strong></p>
<p>结果示例如下所示:</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>
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 |
+-------------+-------------+------------+-----------------------------+
<strong>输出:</strong>
+----------------------+
| immediate_percentage |
+----------------------+
| 50.00 |
+----------------------+
<strong>解释:</strong>
1 号顾客的 1 号订单是首次订单,并且是计划订单。
2 号顾客的 2 号订单是首次订单,并且是即时订单。
3 号顾客的 5 号订单是首次订单,并且是计划订单。
4 号顾客的 7 号订单是首次订单,并且是即时订单。
因此,一半顾客的首次订单是即时的。
</pre>

View File

@ -0,0 +1,80 @@
<p><code>MyNumbers</code> 表:</p>
<div class="original__bRMd">
<div>
<pre>
+-------------+------+
| Column Name | Type |
+-------------+------+
| num | int |
+-------------+------+
该表可能包含重复项换句话说在SQL中该表没有主键
这张表的每一行都含有一个整数。
</pre>
<p>&nbsp;</p>
<p><strong>单一数字</strong> 是在 <code>MyNumbers</code> 表中只出现一次的数字。</p>
<p>找出最大的 <strong>单一数字</strong> 。如果不存在 <strong>单一数字</strong> ,则返回&nbsp;<code>null</code></p>
<p>查询结果如下例所示。</p>
<ptable> </ptable>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>
MyNumbers 表:
+-----+
| num |
+-----+
| 8 |
| 8 |
| 3 |
| 3 |
| 1 |
| 4 |
| 5 |
| 6 |
+-----+
<strong>输出:</strong>
+-----+
| num |
+-----+
| 6 |
+-----+
<strong>解释:</strong>单一数字有 1、4、5 和 6 。
6 是最大的单一数字,返回 6 。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>
MyNumbers table:
+-----+
| num |
+-----+
| 8 |
| 8 |
| 7 |
| 7 |
| 3 |
| 3 |
| 3 |
+-----+
<strong>输出:</strong>
+------+
| num |
+------+
| null |
+------+
<strong>解释:</strong>输入的表中不存在单一数字,所以返回 null 。
</pre>
</div>
</div>
<p>&nbsp;</p>

View File

@ -0,0 +1,80 @@
<p>用户表:&nbsp;<code>Users</code></p>
<pre>
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| user_id | int |
| user_name | varchar |
+-------------+---------+
user_id 是该表的主键(具有唯一值的列)。
该表中的每行包括用户 ID 和用户名。</pre>
<p>&nbsp;</p>
<p>注册表:&nbsp;<code>Register</code></p>
<pre>
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| contest_id | int |
| user_id | int |
+-------------+---------+
(contest_id, user_id) 是该表的主键(具有唯一值的列的组合)。
该表中的每行包含用户的 ID 和他们注册的赛事。</pre>
<p>&nbsp;</p>
<p>编写解决方案统计出各赛事的用户注册百分率,保留两位小数。</p>
<p>返回的结果表按&nbsp;<code>percentage</code>&nbsp;&nbsp;<strong>降序&nbsp;</strong>排序,若相同则按&nbsp;<code>contest_id</code>&nbsp;&nbsp;<strong>升序&nbsp;</strong>排序。</p>
<p>返回结果如下示例所示。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<code><strong>输入:</strong>
Users</code> 表:
+---------+-----------+
| user_id | user_name |
+---------+-----------+
| 6 | Alice |
| 2 | Bob |
| 7 | Alex |
+---------+-----------+
<code>Register</code> 表:
+------------+---------+
| 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 |
+------------+---------+
<strong>输出:</strong>
+------------+------------+
| contest_id | percentage |
+------------+------------+
| 208 | 100.0 |
| 209 | 100.0 |
| 210 | 100.0 |
| 215 | 66.67 |
| 207 | 33.33 |
+------------+------------+
<strong>解释:</strong>
所有用户都注册了 208、209 和 210 赛事,因此这些赛事的注册率为 100% ,我们按 contest_id 的降序排序加入结果表中。
Alice 和 Alex 注册了 215 赛事,注册率为 ((2/3) * 100) = 66.67%
Bob 注册了 207 赛事,注册率为 ((1/3) * 100) = 33.33%</pre>

View File

@ -0,0 +1,69 @@
<p>表:<code>Employee</code>&nbsp;</p>
<pre>
+-------------+---------+
| Column Name | Type |
+-------------+---------+
| empId | int |
| name | varchar |
| supervisor | int |
| salary | int |
+-------------+---------+
empId 是该表中具有唯一值的列。
该表的每一行都表示员工的姓名和 id以及他们的工资和经理的 id。
</pre>
<p>&nbsp;</p>
<p>表:<code>Bonus</code></p>
<pre>
+-------------+------+
| Column Name | Type |
+-------------+------+
| empId | int |
| bonus | int |
+-------------+------+
empId 是该表具有唯一值的列。
empId 是 Employee 表中 empId 的外键(reference 列)。
该表的每一行都包含一个员工的 id 和他们各自的奖金。
</pre>
<p>&nbsp;</p>
<p>编写解决方案,报告每个奖金 <strong>少于</strong> <code>1000</code> 的员工的姓名和奖金数额。</p>
<p><strong>任意顺序</strong> 返回结果表。</p>
<p>结果格式如下所示。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<b>输入:</b>
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 |
+-------+-------+
<b>输出:</b>
+------+-------+
| name | bonus |
+------+-------+
| Brad | null |
| John | null |
| Dan | 500 |
+------+-------+</pre>

View File

@ -0,0 +1,60 @@
<p>表:<code>Employee</code></p>
<pre>
+---------------+---------+
| 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',则否
</pre>
<p>&nbsp;</p>
<p>一个员工可以属于多个部门。当一个员工加入<strong>超过一个部门</strong>的时候,他需要决定哪个部门是他的直属部门。请注意,当员工只加入一个部门的时候,那这个部门将默认为他的直属部门,虽然表记录的值为<code>'N'</code>.</p>
<p>请编写解决方案,查出员工所属的直属部门。</p>
<p>返回结果 <strong>没有顺序要求</strong></p>
<p>返回结果格式如下例子所示:</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>
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 |
+-------------+---------------+--------------+
<strong>输出:</strong>
+-------------+---------------+
| employee_id | department_id |
+-------------+---------------+
| 1 | 1 |
| 2 | 1 |
| 3 | 3 |
| 4 | 3 |
+-------------+---------------+
<strong>解释:</strong>
- 员工 1 的直属部门是 1
- 员工 2 的直属部门是 1
- 员工 3 的直属部门是 3
- 员工 4 的直属部门是 3</pre>
<p>&nbsp;</p>

View File

@ -0,0 +1,17 @@
<p>书店店员有一张链表形式的书单,每个节点代表一本书,节点中的值表示书的编号。为更方便整理书架,店员需要将书单倒过来排列,就可以从最后一本书开始整理,逐一将书放回到书架上。请倒序返回这个书单链表。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>head = [3,6,4,1]
<strong>输出:</strong>[1,4,6,3]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<p><code>0 &lt;= 链表长度 &lt;= 10000</code></p>

View File

@ -0,0 +1,36 @@
<p>读者来到图书馆排队借还书,图书管理员使用两个书车来完成整理借还书的任务。书车中的书从下往上叠加存放,图书管理员每次只能拿取书车顶部的书。排队的读者会有两种操作:</p>
<ul>
<li><code>push(bookID)</code>:把借阅的书籍还到图书馆。</li>
<li><code>pop()</code>:从图书馆中借出书籍。</li>
</ul>
<p>为了保持图书的顺序,图书管理员每次取出供读者借阅的书籍是 <strong>最早</strong> 归还到图书馆的书籍。你需要返回 <strong>每次读者借出书的值</strong></p>
<p>如果没有归还的书可以取出,返回&nbsp;<code>-1</code></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>
["BookQueue", "push", "push", "pop"]
[[], [1], [2], []]
<strong>输出:</strong>[null,null,null,1]
<strong>解释:
</strong>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]</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= bookID &lt;= 10000</code></li>
<li>最多会对 <code>push</code><code>pop</code> 进行 <code>10000</code> 次调用</li>
</ul>
<p>&nbsp;</p>

View File

@ -0,0 +1,39 @@
<pre>
DataFrame <code>products</code>
+-------------+--------+
| Column Name | Type |
+-------------+--------+
| name | object |
| quantity | int |
| price | int |
+-------------+--------+
</pre>
<p>编写一个解决方案,在 <code>quantity</code> 列中将缺失的值填充为&nbsp;<code><strong>0</strong></code></p>
<p>返回结果如下示例所示。</p>
<p>&nbsp;</p>
<strong class="example">示例 1</strong>
<pre>
<strong>输入:
</strong>+-----------------+----------+-------+
| name | quantity | price |
+-----------------+----------+-------+
| Wristwatch | 32 | 135 |
| WirelessEarbuds | None | 821 |
| GolfClubs | None | 9319 |
| Printer | 849 | 3051 |
+-----------------+----------+-------+
<strong>输出:
</strong>+-----------------+----------+-------+
| name | quantity | price |
+-----------------+----------+-------+
| Wristwatch | 32 | 135 |
| WirelessEarbuds | 0 | 821 |
| GolfClubs | 0 | 9319 |
| Printer | 849 | 3051 |
+-----------------+----------+-------+
<b>解释:</b>
Toaster 和 Headphones 的数量被填充为 0。</pre>

View File

@ -0,0 +1,22 @@
<p>某店铺将用于组成套餐的商品记作字符串 <code>goods</code>,其中 <code>goods[i]</code> 表示对应商品。请返回该套餐内所含商品的 <strong>全部排列方式</strong></p>
<p>返回结果 <strong>无顺序要求</strong>,但不能含有重复的元素。</p>
<p>&nbsp;</p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong>goods = "agew"
<strong>输出:</strong>["aegw","aewg","agew","agwe","aweg","awge","eagw","eawg","egaw","egwa","ewag","ewga","gaew","gawe","geaw","gewa","gwae","gwea","waeg","wage","weag","wega","wgae","wgea"]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= goods.length &lt;= 8</code></li>
</ul>
<p>&nbsp;</p>

View File

@ -0,0 +1,53 @@
<p><code>RequestAccepted</code> 表:</p>
<div class="original__bRMd">
<div>
<pre>
+----------------+---------+
| Column Name | Type |
+----------------+---------+
| requester_id | int |
| accepter_id | int |
| accept_date | date |
+----------------+---------+
(requester_id, accepter_id) 是这张表的主键(具有唯一值的列的组合)。
这张表包含发送好友请求的人的 ID ,接收好友请求的人的 ID ,以及好友请求通过的日期。
</pre>
<p>&nbsp;</p>
<p>编写解决方案,找出拥有最多的好友的人和他拥有的好友数目。</p>
<p>生成的测试用例保证拥有最多好友数目的只有 1 个人。</p>
<p>查询结果格式如下例所示。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>
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 |
+--------------+-------------+-------------+
<strong>输出:</strong>
+----+-----+
| id | num |
+----+-----+
| 3 | 3 |
+----+-----+
<strong>解释:</strong>
编号为 3 的人是编号为 1 2 和 4 的人的好友,所以他总共有 3 个好友,比其他人都多。</pre>
<p>&nbsp;</p>
<p><strong>进阶:</strong>在真实世界里,可能会有多个人拥有好友数相同且最多,你能找到所有这些人吗?</p>
</div>
</div>

View File

@ -0,0 +1,33 @@
<p>给定两棵二叉树 <code>tree1</code><code>tree2</code>,判断 <code>tree2</code> 是否以 <code>tree1</code> 的某个节点为根的子树具有 <strong>相同的结构和节点值</strong><br />
注意,<strong>空树&nbsp;</strong>不会是以 <code>tree1</code> 的某个节点为根的子树具有 <strong>相同的结构和节点值</strong></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p>&nbsp;</p>
<p><img alt="" src="https://pic.leetcode.cn/1694684670-vwyIgY-two_tree.png" /></p>
<p>&nbsp;</p>
<pre>
<strong>输入:</strong>tree1 = [1,7,5], tree2 = [6,1]
<strong>输出:</strong>false
<strong>解释:</strong>tree2 与 tree1 的一个子树没有相同的结构和节点值。
</pre>
<p><strong>示例 2</strong></p>
<p><img alt="" src="https://pic.leetcode.cn/1694685602-myWXCv-two_tree_2.png" /></p>
<pre>
<strong>输入:</strong>tree1 = [3,6,7,1,8], tree2 = [6,1]
<strong>输出:</strong>true
<strong>解释:</strong>tree2 与 tree1 的一个子树拥有相同的结构和节点值。即 6 - &gt; 1。</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<p><code>0 &lt;= 节点个数 &lt;= 10000</code></p>

View File

@ -0,0 +1,49 @@
<p>字母迷宫游戏初始界面记作 <code>m x n</code> 二维字符串数组 <code>grid</code>,请判断玩家是否能在 <code>grid</code> 中找到目标单词 <code>target</code><br />
注意:寻找单词时 <strong>必须</strong> 按照字母顺序,通过水平或垂直方向相邻的单元格内的字母构成,同时,同一个单元格内的字母&nbsp;<strong>不允许被重复使用&nbsp;</strong></p>
<p>&nbsp;</p>
<p><img alt="" src="https://assets.leetcode.com/uploads/2020/11/04/word2.jpg" /></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>grid = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], target = "ABCCED"
<strong>输出:</strong>true
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>grid = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], target = "SEE"
<strong>输出:</strong>true
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>grid = [["A","B","C","E"],["S","F","C","S"],["A","D","E","E"]], target = "ABCB"
<strong>输出:</strong>false
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>m == grid.length</code></li>
<li><code>n = grid[i].length</code></li>
<li><code>1 &lt;= m, n &lt;= 6</code></li>
<li><code>1 &lt;= target.length &lt;= 15</code></li>
<li><code>grid</code><code>target</code> 仅由大小写英文字母组成</li>
</ul>
<p>&nbsp;</p>
<p><strong>注意:</strong>本题与主站 79 题相同:<a href="https://leetcode-cn.com/problems/word-search/">https://leetcode-cn.com/problems/word-search/</a></p>
<p>&nbsp;</p>
<p>&nbsp;</p>

View File

@ -0,0 +1,47 @@
<p>你在与一位习惯从右往左阅读的朋友发消息,他发出的文字顺序都与正常相反但单词内容正确,为了和他顺利交流你决定写一个转换程序,把他所发的消息 <code>message</code> 转换为正常语序。</p>
<p>注意:输入字符串 <code>message</code> 中可能会存在前导空格、尾随空格或者单词间的多个空格。返回的结果字符串中,单词间应当仅用单个空格分隔,且不包含任何额外的空格。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong> message = "<code>the sky is blue</code>"
<strong>输出:&nbsp;</strong>"<code>blue is sky the</code>"
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong> message = " &nbsp;hello world! &nbsp;"
<strong>输出:&nbsp;</strong>"world! hello"
<strong>解释: </strong>输入字符串可以在前面或者后面包含多余的空格,但是反转后的字符不能包括。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong> message = "a good &nbsp; example"
<strong>输出:&nbsp;</strong>"example good a"
<strong>解释: </strong>如果两个单词间有多余的空格,将反转后单词间的空格减少到只含一个。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= message.length &lt;= 10^4</code></li>
<li><code>message</code> 中包含英文大小写字母、空格和数字</li>
<li><code>message</code> 中至少有一个单词</li>
<li>&nbsp;</li>
</ul>
<p><strong>注意:</strong></p>
<ul>
<li>本题与主站 151 题相同:<a href="https://leetcode-cn.com/problems/reverse-words-in-a-string/">https://leetcode-cn.com/problems/reverse-words-in-a-string/</a></li>
</ul>
<p>&nbsp;</p>

View File

@ -0,0 +1,112 @@
<p>学生表: <code>Students</code></p>
<pre>
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| student_id | int |
| student_name | varchar |
+---------------+---------+
在 SQL 中,主键为 student_id学生ID
该表内的每一行都记录有学校一名学生的信息。
</pre>
<p>&nbsp;</p>
<p>科目表: <code>Subjects</code></p>
<pre>
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| subject_name | varchar |
+--------------+---------+
在 SQL 中,主键为 subject_name科目名称
每一行记录学校的一门科目名称。
</pre>
<p>&nbsp;</p>
<p>考试表: <code>Examinations</code></p>
<pre>
+--------------+---------+
| Column Name | Type |
+--------------+---------+
| student_id | int |
| subject_name | varchar |
+--------------+---------+
这个表可能包含重复数据(换句话说,在 SQL 中,这个表没有主键)。
学生表里的一个学生修读科目表里的每一门科目。
这张考试表的每一行记录就表示学生表里的某个学生参加了一次科目表里某门科目的测试。
</pre>
<p>&nbsp;</p>
<p>查询出每个学生参加每一门科目测试的次数,结果按 <code>student_id</code><code>subject_name</code> 排序。</p>
<p>查询结构格式如下所示。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>
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 |
+------------+--------------+
<strong>输出:</strong>
+------------+--------------+--------------+----------------+
| 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 |
+------------+--------------+--------------+----------------+
<strong>解释:</strong>
结果表需包含所有学生和所有科目即便测试次数为0
Alice 参加了 3 次数学测试, 2 次物理测试,以及 1 次编程测试;
Bob 参加了 1 次数学测试, 1 次编程测试,没有参加物理测试;
Alex 啥测试都没参加;
John 参加了数学、物理、编程测试各 1 次。
</pre>

View File

@ -0,0 +1,42 @@
<p>某公司组织架构以二叉搜索树形式记录,节点值为处于该职位的员工编号。请返回第 <code>cnt</code> 大的员工编号。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://pic.leetcode.cn/1695101634-kzHKZW-image.png" style="height: 281px; width: 500px;" /></p>
<pre>
<strong>输入:</strong>root = [7, 3, 9, 1, 5], cnt = 2
7
/ \
3 9
/ \
1 5
<strong>输出:</strong>7
</pre>
<p><strong>示例 2</strong></p>
<p><img alt="" src="https://pic.leetcode.cn/1695101636-ESZtLa-image.png" style="height: 281px; width: 500px;" /></p>
<pre>
<strong>输入:</strong> root = [10, 5, 15, 2, 7, null, 20, 1, null, 6, 8], cnt = 4
10
/ \
5 15
/ \ \
2 7 20
/ / \
1 6 8
<strong>输出:</strong> 8</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li>1 ≤ cnt&nbsp;≤ 二叉搜索树元素个数</li>
</ul>
<p>&nbsp;</p>

View File

@ -0,0 +1,21 @@
<p>设备中存有 <code>n</code> 个文件,文件 <code>id</code> 记于数组 <code>documents</code>。若文件 <code>id</code> 相同,则定义为该文件存在副本。请返回任一存在副本的文件 <code>id</code></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>documents = [2, 5, 3, 0, 5, 0]
<strong>输出:</strong>0 或 5
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>0 ≤ documents[i] ≤ n-1</code></li>
<li><code>2 &lt;= n &lt;= 100000</code></li>
</ul>
<p>&nbsp;</p>

View File

@ -0,0 +1,43 @@
<p><code>m</code>*<code>n</code> 的二维数组 <code>plants</code> 记录了园林景观的植物排布情况,具有以下特性:</p>
<ul>
<li>每行中,每棵植物的右侧相邻植物不矮于该植物;</li>
<li>每列中,每棵植物的下侧相邻植物不矮于该植物。</li>
</ul>
<p>&nbsp;</p>
<p>请判断 <code>plants</code> 中是否存在目标高度值 <code>target</code></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>plants = [[2,3,6,8],[4,5,8,9],[5,9,10,12]], target = 8
<strong>输出:</strong>true
</pre>
<p>&nbsp;</p>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>plants = [[1,3,5],[2,5,7]], target = 4
<strong>输出:</strong>false
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>0 &lt;= n &lt;= 1000</code></li>
<li><code>0 &lt;= m &lt;= 1000</code></li>
</ul>
<p>注意:本题与主站 240 题相同:<a href="https://leetcode-cn.com/problems/search-a-2d-matrix-ii/" rel="noopener noreferrer" target="_blank">https://leetcode-cn.com/problems/search-a-2d-matrix-ii/</a></p>
<p>&nbsp;</p>

View File

@ -0,0 +1,54 @@
<p>将一个 <strong>二叉搜索树</strong> 就地转化为一个 <strong>已排序的双向循环链表</strong></p>
<p>对于双向循环列表,你可以将左右孩子指针作为双向循环链表的前驱和后继指针,第一个节点的前驱是最后一个节点,最后一个节点的后继是第一个节点。</p>
<p>特别地,我们希望可以 <strong>就地</strong> 完成转换操作。当转化完成以后,树中节点的左指针需要指向前驱,树中节点的右指针需要指向后继。还需要返回链表中最小元素的指针。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>root = [4,2,5,1,3]
<img src="https://assets.leetcode.com/uploads/2018/10/12/bstdllreturndll.png" />
<strong>输出:</strong>[1,2,3,4,5]
<strong>解释:</strong>下图显示了转化后的二叉搜索树,实线表示后继关系,虚线表示前驱关系。
<img src="https://assets.leetcode.com/uploads/2018/10/12/bstdllreturnbst.png" />
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>root = [2,1,3]
<strong>输出:</strong>[1,2,3]
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>root = []
<strong>输出:</strong>[]
<strong>解释:</strong>输入是空树,所以输出也是空链表。
</pre>
<p><strong>示例 4</strong></p>
<pre>
<strong>输入:</strong>root = [1]
<strong>输出:</strong>[1]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>-1000 &lt;= Node.val &lt;= 1000</code></li>
<li><code>Node.left.val &lt; Node.val &lt; Node.right.val</code></li>
<li><code>Node.val</code> 的所有值都是独一无二的</li>
<li><code>0 &lt;= Number of Nodes &lt;= 2000</code></li>
</ul>
<p>注意:本题与主站 426 题相同:<a href="https://leetcode-cn.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list/" rel="noopener noreferrer" target="_blank">https://leetcode-cn.com/problems/convert-binary-search-tree-to-sorted-doubly-linked-list/</a></p>

View File

@ -0,0 +1,73 @@
<p>表:<code>Prices</code></p>
<pre>
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| product_id | int |
| start_date | date |
| end_date | date |
| price | int |
+---------------+---------+
(product_idstart_dateend_date) 是 <code>prices</code> 表的主键(具有唯一值的列的组合)。
<code>prices</code> 表的每一行表示的是某个产品在一段时期内的价格。
每个产品的对应时间段是不会重叠的,这也意味着同一个产品的价格时段不会出现交叉。</pre>
<p>&nbsp;</p>
<p>表:<code>UnitsSold</code></p>
<pre>
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| product_id | int |
| purchase_date | date |
| units | int |
+---------------+---------+
<span style="white-space: pre-wrap;">该表可能包含重复数据</span>
<span style="white-space: pre-wrap;"></span>表的每一行表示的是每种产品的出售日期,单位和产品 id。</pre>
<p>&nbsp;</p>
<p>编写解决方案以查找每种产品的平均售价。<code>average_price</code> 应该 <strong>四舍五入到小数点后两位</strong></p>
<p>返回结果表 <strong>无顺序要求</strong></p>
<p>结果格式如下例所示。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>
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 |
+------------+---------------+-------+
<strong>输出:</strong>
+------------+---------------+
| product_id | average_price |
+------------+---------------+
| 1 | 6.96 |
| 2 | 16.96 |
+------------+---------------+
<strong>解释:</strong>
平均售价 = 产品总价 / 销售的产品数量。
产品 1 的平均售价 = ((100 * 5)+(15 * 20) )/ 115 = 6.96
产品 2 的平均售价 = ((200 * 15)+(30 * 30) )/ 230 = 16.96</pre>

View File

@ -0,0 +1,64 @@
<p>给定一个长度为 <code>n</code> 的整数数组 <code>nums</code> ,其中 <code>nums</code> 是范围为 <code>[1n]</code> 的整数的排列。还提供了一个 2D 整数数组&nbsp;<code>sequences</code>&nbsp;,其中&nbsp;<code>sequences[i]</code>&nbsp;&nbsp;<code>nums</code>&nbsp;的子序列。<br />
检查 <code>nums</code> 是否是唯一的最短&nbsp;<strong>超序列</strong> 。最短 <strong>超序列</strong><strong>长度最短</strong> 的序列,并且所有序列&nbsp;<code>sequences[i]</code>&nbsp;都是它的子序列。对于给定的数组&nbsp;<code>sequences</code>&nbsp;,可能存在多个有效的 <strong>超序列</strong></p>
<ul>
<li>例如,对于&nbsp;<code>sequences = [[1,2],[1,3]]</code>&nbsp;,有两个最短的 <strong>超序列</strong> <code>[1,2,3]</code><code>[1,3,2]</code></li>
<li>而对于&nbsp;<code>sequences = [[1,2],[1,3],[1,2,3]]</code>&nbsp;,唯一可能的最短 <strong>超序列</strong><code>[1,2,3]</code><code>[1,2,3,4]</code> 是可能的超序列,但不是最短的。</li>
</ul>
<p><em>如果 <code>nums</code> 是序列的唯一最短 <strong>超序列</strong> ,则返回 <code>true</code> ,否则返回 <code>false</code></em><br />
<strong>子序列</strong> 是一个可以通过从另一个序列中删除一些元素或不删除任何元素,而不改变其余元素的顺序的序列。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = [1,2,3], sequences = [[1,2],[1,3]]
<strong>输出:</strong>false
<strong>解释:</strong>有两种可能的超序列:[1,2,3]和[1,3,2]。
序列 [1,2] 是[<u><strong>1,2</strong></u>,3]和[<u><strong>1</strong></u>,3,<u><strong>2</strong></u>]的子序列。
序列 [1,3] 是[<u><strong>1</strong></u>,2,<u><strong>3</strong></u>]和[<u><strong>1,3</strong></u>,2]的子序列。
因为 nums 不是唯一最短的超序列所以返回false。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [1,2,3], sequences = [[1,2]]
<strong>输出:</strong>false
<strong>解释:</strong>最短可能的超序列为 [1,2]。
序列 [1,2] 是它的子序列:[<u><strong>1,2</strong></u>]。
因为 nums 不是最短的超序列所以返回false。
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>nums = [1,2,3], sequences = [[1,2],[1,3],[2,3]]
<strong>输出:</strong>true
<strong>解释:</strong>最短可能的超序列为[1,2,3]。
序列 [1,2] 是它的一个子序列:[<strong>1,2</strong>,3]。
序列 [1,3] 是它的一个子序列:[<u><strong>1</strong></u>,2,<u><strong>3</strong></u>]。
序列 [2,3] 是它的一个子序列:[1,<u><strong>2,3</strong></u>]。
因为 nums 是唯一最短的超序列所以返回true。</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == nums.length</code></li>
<li><code>1 &lt;= n &lt;= 10<sup>4</sup></code></li>
<li><code>nums</code>&nbsp;&nbsp;<code>[1, n]</code>&nbsp;范围内所有整数的排列</li>
<li><code>1 &lt;= sequences.length &lt;= 10<sup>4</sup></code></li>
<li><code>1 &lt;= sequences[i].length &lt;= 10<sup>4</sup></code></li>
<li><code>1 &lt;= sum(sequences[i].length) &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= sequences[i][j] &lt;= n</code></li>
<li><code>sequences</code>&nbsp;的所有数组都是 <strong>唯一 </strong></li>
<li><code>sequences[i]</code>&nbsp;&nbsp;<code>nums</code> 的一个子序列</li>
</ul>
<p>&nbsp;</p>
<p>注意:本题与主站 444&nbsp;题相同:<a href="https://leetcode-cn.com/problems/sequence-reconstruction/">https://leetcode-cn.com/problems/sequence-reconstruction/</a></p>

View File

@ -0,0 +1,32 @@
<p>仓库管理员以数组 <code>stock</code> 形式记录商品库存表。<code>stock[i]</code> 表示商品 <code>id</code>,可能存在重复。原库存表按商品 <code>id</code> 升序排列。现因突发情况需要进行商品紧急调拨,管理员将这批商品 <code>id</code> 提前依次整理至库存表最后。请你找到并返回库存表中编号的 <strong>最小的元素</strong> 以便及时记录本次调拨。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>stock =<strong> </strong>[4,5,8,3,4]
<strong>输出:</strong>3
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>stock = [5,7,9,1,2]
<strong>输出:</strong>1
</pre>
<p>&nbsp;</p>
<p>提示:</p>
<ul>
<li>1 &lt;= stock.length &lt;= 5000</li>
<li>-5000 &lt;= stock[i] &lt;= 5000</li>
</ul>
<p>&nbsp;</p>
<p>注意:本题与主站 154 题相同:<a href="https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array-ii/">https://leetcode-cn.com/problems/find-minimum-in-rotated-sorted-array-ii/</a></p>
<p>&nbsp;</p>

View File

@ -0,0 +1,22 @@
<p>仓库管理员以数组 <code>stock</code> 形式记录商品库存表。<code>stock[i]</code> 表示商品 <code>id</code>,可能存在重复。请返回库存表中数量大于 <code>stock.length / 2</code> 的商品 <code>id</code></p>
<p>&nbsp;</p>
<p><strong>示例&nbsp;1:</strong></p>
<pre>
<strong>输入: </strong>stock = [6, 1, 3, 1, 1, 1]
<strong>输出: </strong>1</pre>
<p>&nbsp;</p>
<p><strong>限制:</strong></p>
<ul>
<li><code>1 &lt;= stock.length &lt;= 50000</code></li>
<li>给定数组为非空数组,且存在结果数字</li>
</ul>
<p>&nbsp;</p>
<p>注意:本题与主站 169 题相同:<a href="https://leetcode-cn.com/problems/majority-element/">https://leetcode-cn.com/problems/majority-element/</a></p>

View File

@ -0,0 +1,27 @@
<p>仓库管理员以数组 <code>stock</code> 形式记录商品库存表,其中 <code>stock[i]</code> 表示对应商品库存余量。请返回库存余量最少的 <code>cnt</code> 个商品余量,返回&nbsp;<strong>顺序不限</strong></p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>stock = [2,5,7,4], cnt = 1
<strong>输出:</strong>[2]
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>stock = [0,2,3,6], cnt = 2
<strong>输出:</strong>[0,2] 或 [2,0]</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>0 &lt;= cnt &lt;= stock.length &lt;= 10000<br />
0 &lt;= stock[i] &lt;= 10000</code></li>
</ul>
<p>&nbsp;</p>

View File

@ -0,0 +1,22 @@
<p>一棵圣诞树记作根节点为 <code>root</code> 的二叉树,节点值为该位置装饰彩灯的颜色编号。请按照从 <strong></strong><strong></strong> 的顺序返回每一层彩灯编号。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://pic.leetcode.cn/1694758674-XYrUiV-%E5%89%91%E6%8C%87%20Offer%2032%20-%20I_%E7%A4%BA%E4%BE%8B1.png" /></p>
<pre>
<strong>输入:</strong>root = [8,17,21,18,null,null,6]
<strong>输出:</strong>[8,17,21,18,6]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ol>
<li><code>节点总数 &lt;= 1000</code></li>
</ol>
<p>&nbsp;</p>

View File

@ -0,0 +1,22 @@
<p>一棵圣诞树记作根节点为 <code>root</code> 的二叉树,节点值为该位置装饰彩灯的颜色编号。请按照从左到右的顺序返回每一层彩灯编号,每一层的结果记录于一行。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://pic.leetcode.cn/1694758674-XYrUiV-%E5%89%91%E6%8C%87%20Offer%2032%20-%20I_%E7%A4%BA%E4%BE%8B1.png" /></p>
<pre>
<strong>输入:</strong>root = [8,17,21,18,null,null,6]
<strong>输出:</strong>[[8],[17,21],[18,6]]
</pre>
<p><strong>提示:</strong></p>
<ol>
<li><code>节点总数 &lt;= 1000</code></li>
</ol>
<p>注意:本题与主站 102 题相同:<a href="https://leetcode-cn.com/problems/binary-tree-level-order-traversal/">https://leetcode-cn.com/problems/binary-tree-level-order-traversal/</a></p>
<p>&nbsp;</p>

View File

@ -0,0 +1,27 @@
<p>一棵圣诞树记作根节点为 <code>root</code> 的二叉树,节点值为该位置装饰彩灯的颜色编号。请按照如下规则记录彩灯装饰结果:</p>
<ul>
<li>第一层按照从左到右的顺序记录</li>
<li>除第一层外每一层的记录顺序均与上一层相反。即第一层为从左到右,第二层为从右到左。</li>
</ul>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<p><img alt="" src="https://pic.leetcode.cn/1694758674-XYrUiV-%E5%89%91%E6%8C%87%20Offer%2032%20-%20I_%E7%A4%BA%E4%BE%8B1.png" /></p>
<pre>
<strong>输入:</strong>root = [8,17,21,18,null,null,6]
<strong>输出:</strong>[[8],[21,17],[18,6]]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>节点总数 &lt;= 1000</code></li>
</ul>
<p>&nbsp;</p>

View File

@ -0,0 +1,29 @@
<p>给你一个整数 <code>n</code> ,请你找出所有可能含 <code>n</code> 个节点的 <strong>真二叉树</strong> ,并以列表形式返回。答案中每棵树的每个节点都必须符合 <code>Node.val == 0</code></p>
<p>答案的每个元素都是一棵真二叉树的根节点。你可以按 <strong>任意顺序</strong> 返回最终的真二叉树列表<strong></strong></p>
<p><strong>真二叉树</strong> 是一类二叉树,树中每个节点恰好有 <code>0</code><code>2</code> 个子节点。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<img alt="" src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/08/22/fivetrees.png" style="width: 700px; height: 400px;" />
<pre>
<strong>输入:</strong>n = 7
<strong>输出:</strong>[[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]]
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>n = 3
<strong>输出:</strong>[[0,0,0]]
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= n &lt;= 20</code></li>
</ul>

View File

@ -0,0 +1,29 @@
<p>给你两个字符串&nbsp;<code>haystack</code><code>needle</code> ,请你在 <code>haystack</code> 字符串中找出 <code>needle</code> 字符串的第一个匹配项的下标(下标从 0 开始)。如果&nbsp;<code>needle</code> 不是 <code>haystack</code> 的一部分,则返回&nbsp; <code>-1</code><strong> </strong></p>
<p>&nbsp;</p>
<p><strong class="example">示例 1</strong></p>
<pre>
<strong>输入:</strong>haystack = "sadbutsad", needle = "sad"
<strong>输出:</strong>0
<strong>解释:</strong>"sad" 在下标 0 和 6 处匹配。
第一个匹配项的下标是 0 ,所以返回 0 。
</pre>
<p><strong class="example">示例 2</strong></p>
<pre>
<strong>输入:</strong>haystack = "leetcode", needle = "leeto"
<strong>输出:</strong>-1
<strong>解释:</strong>"leeto" 没有在 "leetcode" 中出现,所以返回 -1 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= haystack.length, needle.length &lt;= 10<sup>4</sup></code></li>
<li><code>haystack</code><code>needle</code> 仅由小写英文字符组成</li>
</ul>

View File

@ -0,0 +1,42 @@
<p>数对 <code>(a,b)</code> 由整数 <code>a</code><code>b</code> 组成,其数对距离定义为 <code>a</code><code>b</code> 的绝对差值。</p>
<p>给你一个整数数组 <code>nums</code> 和一个整数 <code>k</code> ,数对由 <code>nums[i]</code><code>nums[j]</code> 组成且满足 <code>0 &lt;= i &lt; j &lt; nums.length</code> 。返回 <strong>所有数对距离中</strong><code>k</code> 小的数对距离。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>nums = [1,3,1], k = 1
<strong>输出:</strong>0
<strong>解释:</strong>数对和对应的距离如下:
(1,3) -&gt; 2
(1,1) -&gt; 0
(3,1) -&gt; 2
距离第 1 小的数对是 (1,1) ,距离为 0 。
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>nums = [1,1,1], k = 2
<strong>输出:</strong>0
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>nums = [1,6,1], k = 3
<strong>输出:</strong>5
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>n == nums.length</code></li>
<li><code>2 &lt;= n &lt;= 10<sup>4</sup></code></li>
<li><code>0 &lt;= nums[i] &lt;= 10<sup>6</sup></code></li>
<li><code>1 &lt;= k &lt;= n * (n - 1) / 2</code></li>
</ul>

View File

@ -0,0 +1,29 @@
<p>某班级学号记录系统发生错乱,原整数学号序列 <code>[0,1,2,3,4,...]</code> 分隔符丢失后变为 <code>01234...</code> 的字符序列。请实现一个函数返回该字符序列中的第 <code>k</code> 位数字。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>k = 5
<strong>输出:</strong>5
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>k = 12
<strong>输出:</strong>1
<strong>解释:</strong>第 12 位数字在序列 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... 里是 1 ,它是 11 的一部分。</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>0 &lt;= k &lt;&nbsp;2<sup>31</sup></code></li>
</ul>
<p>注意:本题与主站 400 题相同:<a href="https://leetcode-cn.com/problems/nth-digit/">https://leetcode-cn.com/problems/nth-digit/</a></p>
<p>&nbsp;</p>

View File

@ -0,0 +1,83 @@
<p>请你来实现一个&nbsp;<code>myAtoi(string s)</code>&nbsp;函数,使其能将字符串转换成一个 32 位有符号整数(类似 C/C++ 中的 <code>atoi</code> 函数)。</p>
<p>函数&nbsp;<code>myAtoi(string s)</code> 的算法如下:</p>
<ol>
<li>读入字符串并丢弃无用的前导空格</li>
<li>检查下一个字符(假设还未到字符末尾)为正还是负号,读取该字符(如果有)。 确定最终结果是负数还是正数。 如果两者都不存在,则假定结果为正。</li>
<li>读入下一个字符,直到到达下一个非数字字符或到达输入的结尾。字符串的其余部分将被忽略。</li>
<li>将前面步骤读入的这些数字转换为整数(即,"123" -&gt; 123 "0032" -&gt; 32。如果没有读入数字则整数为 <code>0</code> 。必要时更改符号(从步骤 2 开始)。</li>
<li>如果整数数超过 32 位有符号整数范围 <code>[2<sup>31</sup>,&nbsp; 2<sup>31&nbsp;</sup> 1]</code> ,需要截断这个整数,使其保持在这个范围内。具体来说,小于 <code>2<sup>31</sup></code> 的整数应该被固定为 <code>2<sup>31</sup></code> ,大于 <code>2<sup>31&nbsp;</sup> 1</code> 的整数应该被固定为 <code>2<sup>31&nbsp;</sup> 1</code></li>
<li>返回整数作为最终结果。</li>
</ol>
<p><strong>注意:</strong></p>
<ul>
<li>本题中的空白字符只包括空格字符 <code>' '</code></li>
<li>除前导空格或数字后的其余字符串外,<strong>请勿忽略</strong> 任何其他字符。</li>
</ul>
<p>&nbsp;</p>
<p><strong>示例&nbsp;1</strong></p>
<pre>
<strong>输入:</strong>s = "42"
<strong>输出:</strong>42
<strong>解释:</strong>加粗的字符串为已经读入的字符,插入符号是当前读取的字符。
第 1 步:"42"(当前没有读入字符,因为没有前导空格)
^
第 2 步:"42"(当前没有读入字符,因为这里不存在 '-' 或者 '+'
^
第 3 步:"<u>42</u>"(读入 "42"
^
解析得到整数 42 。
由于 "42" 在范围 [-2<sup>31</sup>, 2<sup>31</sup> - 1] 内,最终结果为 42 。</pre>
<p><strong>示例&nbsp;2</strong></p>
<pre>
<strong>输入:</strong>s = " -42"
<strong>输出:</strong>-42
<strong>解释:</strong>
第 1 步:"<u><strong> </strong></u>-42"(读入前导空格,但忽视掉)
^
第 2 步:" <u><strong>-</strong></u>42"(读入 '-' 字符,所以结果应该是负数)
^
第 3 步:" <u><strong>-42</strong></u>"(读入 "42"
^
解析得到整数 -42 。
由于 "-42" 在范围 [-2<sup>31</sup>, 2<sup>31</sup> - 1] 内,最终结果为 -42 。
</pre>
<p><strong>示例&nbsp;3</strong></p>
<pre>
<strong>输入:</strong>s = "4193 with words"
<strong>输出:</strong>4193
<strong>解释:</strong>
第 1 步:"4193 with words"(当前没有读入字符,因为没有前导空格)
^
第 2 步:"4193 with words"(当前没有读入字符,因为这里不存在 '-' 或者 '+'
^
第 3 步:"<u>4193</u> with words"(读入 "4193";由于下一个字符不是一个数字,所以读入停止)
^
解析得到整数 4193 。
由于 "4193" 在范围 [-2<sup>31</sup>, 2<sup>31</sup> - 1] 内,最终结果为 4193 。
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>0 &lt;= s.length &lt;= 200</code></li>
<li><code>s</code> 由英文字母(大写和小写)、数字(<code>0-9</code>)、<code>' '</code><code>'+'</code><code>'-'</code><code>'.'</code> 组成</li>
</ul>
<p>&nbsp;</p>
<p>注意:本题与主站 8 题相同:<a href="https://leetcode-cn.com/problems/string-to-integer-atoi/">https://leetcode-cn.com/problems/string-to-integer-atoi/</a></p>
<p>&nbsp;</p>

View File

@ -0,0 +1,9 @@
<p>实现一个十进制数字报数程序,请按照数字从小到大的顺序返回一个整数数列,该数列从数字 <code>1</code> 开始,到最大的正整数 <code>cnt</code> 位数字结束。</p>
<p>&nbsp;</p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong>cnt = 2
<strong>输出:</strong>[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]</pre>

View File

@ -0,0 +1,43 @@
<p>某套连招动作记作序列 <code>arr</code>,其中 <code>arr[i]</code> 为第 <code>i</code> 个招式的名字。请返回 <code>arr</code> 中最多可以出连续不重复的多少个招式。</p>
<p>&nbsp;</p>
<p><strong>示例&nbsp;1:</strong></p>
<pre>
<strong>输入: </strong>arr = "dbascDdad"
<strong>输出: </strong>6
<strong>解释:</strong> 因为连续且最长的招式序列是 "dbascD" 或 "bascDd",所以其长度为 6。
</pre>
<p><strong>示例 2:</strong></p>
<pre>
<strong>输入: </strong>arr = "KKK"
<strong>输出: </strong>1
<strong>解释: </strong>因为无重复字符的最长子串是 <code>"K"</code>,所以其长度为 1。
</pre>
<p><strong>示例 3:</strong></p>
<pre>
<strong>输入: </strong>arr = "pwwkew"
<strong>输出: </strong>3
<strong>解释: </strong>因为连续且最长的招式序列是 "wke",所以其长度为 3。&nbsp;
请注意区分 <strong>子串</strong><strong>子序列</strong> 的概念:你的答案必须是 <strong>连续招式</strong> 的长度,也就是 <strong>子串</strong>。而 "pwke" 是一个非连续的 <strong>子序列</strong>,不是 <strong>子串</strong>
</pre>
<p>&nbsp;</p>
<p>提示:</p>
<ul>
<li><code>0 &lt;= arr.length &lt;= 40000</code></li>
<li><code>arr</code> 由英文字母、数字、符号和空格组成。</li>
</ul>
<p>&nbsp;</p>
<p>注意:本题与主站 3 题相同:<a href="https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/">https://leetcode-cn.com/problems/longest-substring-without-repeating-characters/</a></p>
<p>&nbsp;</p>

View File

@ -0,0 +1,23 @@
<p>某套连招动作记作仅由小写字母组成的序列 <code>arr</code>,其中 <code>arr[i]</code><code>i</code> 个招式的名字。请返回第一个只出现一次的招式名称,如不存在请返回空格。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>arr = "abbccdeff"
<strong>输出:</strong>'a'
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>arr = "ccdd"
<strong>输出:</strong>' '
</pre>
<p>&nbsp;</p>
<p><strong>限制:</strong></p>
<p><code>0 &lt;= arr.length&nbsp;&lt;= 50000</code></p>

View File

@ -0,0 +1,46 @@
<p>产品数据表: <code>Products</code></p>
<pre>
+---------------+---------+
| Column Name | Type |
+---------------+---------+
| product_id | int |
| new_price | int |
| change_date | date |
+---------------+---------+
(product_id, change_date) 是此表的主键(具有唯一值的列组合)。
这张表的每一行分别记录了 某产品 在某个日期 更改后 的新价格。</pre>
<p>&nbsp;</p>
<p>编写一个解决方案,找出在&nbsp;<code>2019-08-16</code><strong> </strong>时全部产品的价格,假设所有产品在修改前的价格都是&nbsp;<code>10</code><strong></strong></p>
<p><strong>任意顺序 </strong>返回结果表。</p>
<p>结果格式如下例所示。</p>
<p>&nbsp;</p>
<p><strong>示例 1:</strong></p>
<pre>
<strong>输入:</strong>
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 |
+------------+-----------+-------------+
<strong>输出:</strong>
+------------+-------+
| product_id | price |
+------------+-------+
| 2 | 50 |
| 1 | 35 |
| 3 | 10 |
+------------+-------+</pre>

View File

@ -0,0 +1,58 @@
<p>表: <code>Accounts</code></p>
<pre>
+-------------+------+
| 列名 | 类型 |
+-------------+------+
| account_id | int |
| income | int |
+-------------+------+
在 SQL 中account_id&nbsp;是这个表的主键。
每一行都包含一个银行帐户的月收入的信息。
</pre>
<p>&nbsp;</p>
<p>查询每个工资类别的银行账户数量。&nbsp;工资类别如下:</p>
<ul>
<li><code>"Low Salary"</code>:所有工资 <strong>严格低于</strong> <code>20000</code> 美元。</li>
<li><code>"Average Salary"</code> <strong>包含</strong> 范围内的所有工资&nbsp;<code>[$20000,&nbsp;$50000]</code></li>
<li>
<p><code>"High Salary"</code>:所有工资 <strong>严格大于</strong> <code>50000</code> 美元。</p>
</li>
</ul>
<p>结果表 <strong>必须</strong> 包含所有三个类别。&nbsp;如果某个类别中没有帐户,则报告&nbsp;<code>0</code></p>
<p><strong>任意顺序</strong> 返回结果表。</p>
<p>查询结果格式如下示例。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<b>输入:</b>
Accounts 表:
+------------+--------+
| account_id | income |
+------------+--------+
| 3 | 108939 |
| 2 | 12747 |
| 8 | 87709 |
| 6 | 91796 |
+------------+--------+
<strong>输出:</strong>
+----------------+----------------+
| category | accounts_count |
+----------------+----------------+
| Low Salary | 1 |
| Average Salary | 0 |
| High Salary | 3 |
+----------------+----------------+
<strong>解释:</strong>
低薪: 有一个账户 2.
中等薪水: 没有.
高薪: 有三个账户,他们是 3, 6和 8.</pre>

View File

@ -0,0 +1,55 @@
<p>给出长度相同的两个字符串<code>s1</code>&nbsp;<code>s2</code>&nbsp;,还有一个字符串&nbsp;<code>baseStr</code>&nbsp;</p>
<p>其中 &nbsp;<code>s1[i]</code>&nbsp;&nbsp;<code>s2[i]</code>&nbsp; 是一组等价字符。</p>
<ul>
<li>举个例子,如果&nbsp;<code>s1 = "abc"</code>&nbsp;<code>s2 = "cde"</code>,那么就有&nbsp;<code>'a' == 'c', 'b' == 'd', 'c' == 'e'</code></li>
</ul>
<p>等价字符遵循任何等价关系的一般规则:</p>
<ul>
<li><strong>&nbsp;自反性&nbsp;</strong><code>'a' == 'a'</code></li>
<li>&nbsp;<strong>对称性&nbsp;</strong><code>'a' == 'b'</code> 则必定有 <code>'b' == 'a'</code></li>
<li>&nbsp;<strong>传递性</strong> <code>'a' == 'b'</code><code>'b' == 'c'</code> 就表明 <code>'a' == 'c'</code></li>
</ul>
<p>例如,&nbsp;<code>s1 = "abc"</code>&nbsp;&nbsp;<code>s2 = "cde"</code>&nbsp;的等价信息和之前的例子一样,那么&nbsp;<code>baseStr = "eed"</code>&nbsp;, <code>"acd"</code>&nbsp;&nbsp;<code>"aab"</code>,这三个字符串都是等价的,而&nbsp;<code>"aab"</code>&nbsp;&nbsp;<code>baseStr</code>&nbsp;的按字典序最小的等价字符串</p>
<p>利用<em>&nbsp;</em><code>s1</code>&nbsp;&nbsp;<code>s2</code>&nbsp;的等价信息,找出并返回<em>&nbsp;</em><code>baseStr</code><em>&nbsp;</em>的按字典序排列最小的等价字符串。</p>
<p>&nbsp;</p>
<p><strong>示例 1</strong></p>
<pre>
<strong>输入:</strong>s1 = "parker", s2 = "morris", baseStr = "parser"
<strong>输出:</strong>"makkek"
<strong>解释:</strong>根据 <code>A</code><code>B 中的等价信息,</code>我们可以将这些字符分为 <code>[m,p]</code>, <code>[a,o]</code>, <code>[k,r,s]</code>, <code>[e,i] 共 4 组</code>。每组中的字符都是等价的,并按字典序排列。所以答案是 <code>"makkek"</code>
</pre>
<p><strong>示例 2</strong></p>
<pre>
<strong>输入:</strong>s1 = "hello", s2 = "world", baseStr = "hold"
<strong>输出:</strong>"hdld"
<strong>解释:</strong>根据 <code>A</code><code>B 中的等价信息,</code>我们可以将这些字符分为 <code>[h,w]</code>, <code>[d,e,o]</code>, <code>[l,r] 共 3 组</code>。所以只有 S 中的第二个字符 <code>'o'</code> 变成 <code>'d',最后答案为 </code><code>"hdld"</code>
</pre>
<p><strong>示例 3</strong></p>
<pre>
<strong>输入:</strong>s1 = "leetcode", s2 = "programs", baseStr = "sourcecode"
<strong>输出:</strong>"aauaaaaada"
<strong>解释:</strong>我们可以把 A 和 B 中的等价字符分为 <code>[a,o,e,r,s,c]</code>, <code>[l,p]</code>, <code>[g,t]</code><code>[d,m] 共 4 组</code>,因此 <code>S</code> 中除了 <code>'u'</code><code>'d'</code> 之外的所有字母都转化成了 <code>'a'</code>,最后答案为 <code>"aauaaaaada"</code>
</pre>
<p>&nbsp;</p>
<p><strong>提示:</strong></p>
<ul>
<li><code>1 &lt;= s1.length, s2.length, baseStr &lt;= 1000</code></li>
<li><code>s1.length == s2.length</code></li>
<li>字符串<code>s1</code>,&nbsp;<code>s2</code>, and&nbsp;<code>baseStr</code>&nbsp;仅由从&nbsp;<code>'a'</code>&nbsp;<code>'z'</code>&nbsp;的小写英文字母组成。</li>
</ul>

Some files were not shown because too many files have changed in this diff Show More