mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
192 lines
38 KiB
JSON
192 lines
38 KiB
JSON
{
|
||
"data": {
|
||
"question": {
|
||
"questionId": "1470",
|
||
"questionFrontendId": "1348",
|
||
"categoryTitle": "Algorithms",
|
||
"boundTopicId": 88112,
|
||
"title": "Tweet Counts Per Frequency",
|
||
"titleSlug": "tweet-counts-per-frequency",
|
||
"content": "<p>A social media company is trying to monitor activity on their site by analyzing the number of tweets that occur in select periods of time. These periods can be partitioned into smaller <strong>time chunks</strong> based on a certain frequency (every <strong>minute</strong>, <strong>hour</strong>, or <strong>day</strong>).</p>\n\n<p>For example, the period <code>[10, 10000]</code> (in <strong>seconds</strong>) would be partitioned into the following <strong>time chunks</strong> with these frequencies:</p>\n\n<ul>\n\t<li>Every <strong>minute</strong> (60-second chunks): <code>[10,69]</code>, <code>[70,129]</code>, <code>[130,189]</code>, <code>...</code>, <code>[9970,10000]</code></li>\n\t<li>Every <strong>hour</strong> (3600-second chunks): <code>[10,3609]</code>, <code>[3610,7209]</code>, <code>[7210,10000]</code></li>\n\t<li>Every <strong>day</strong> (86400-second chunks): <code>[10,10000]</code></li>\n</ul>\n\n<p>Notice that the last chunk may be shorter than the specified frequency's chunk size and will always end with the end time of the period (<code>10000</code> in the above example).</p>\n\n<p>Design and implement an API to help the company with their analysis.</p>\n\n<p>Implement the <code>TweetCounts</code> class:</p>\n\n<ul>\n\t<li><code>TweetCounts()</code> Initializes the <code>TweetCounts</code> object.</li>\n\t<li><code>void recordTweet(String tweetName, int time)</code> Stores the <code>tweetName</code> at the recorded <code>time</code> (in <strong>seconds</strong>).</li>\n\t<li><code>List<Integer> getTweetCountsPerFrequency(String freq, String tweetName, int startTime, int endTime)</code> Returns a list of integers representing the number of tweets with <code>tweetName</code> in each <strong>time chunk</strong> for the given period of time <code>[startTime, endTime]</code> (in <strong>seconds</strong>) and frequency <code>freq</code>.\n\t<ul>\n\t\t<li><code>freq</code> is one of <code>"minute"</code>, <code>"hour"</code>, or <code>"day"</code> representing a frequency of every <strong>minute</strong>, <strong>hour</strong>, or <strong>day</strong> respectively.</li>\n\t</ul>\n\t</li>\n</ul>\n\n<p> </p>\n<p><strong class=\"example\">Example:</strong></p>\n\n<pre>\n<strong>Input</strong>\n["TweetCounts","recordTweet","recordTweet","recordTweet","getTweetCountsPerFrequency","getTweetCountsPerFrequency","recordTweet","getTweetCountsPerFrequency"]\n[[],["tweet3",0],["tweet3",60],["tweet3",10],["minute","tweet3",0,59],["minute","tweet3",0,60],["tweet3",120],["hour","tweet3",0,210]]\n\n<strong>Output</strong>\n[null,null,null,null,[2],[2,1],null,[4]]\n\n<strong>Explanation</strong>\nTweetCounts tweetCounts = new TweetCounts();\ntweetCounts.recordTweet("tweet3", 0); // New tweet "tweet3" at time 0\ntweetCounts.recordTweet("tweet3", 60); // New tweet "tweet3" at time 60\ntweetCounts.recordTweet("tweet3", 10); // New tweet "tweet3" at time 10\ntweetCounts.getTweetCountsPerFrequency("minute", "tweet3", 0, 59); // return [2]; chunk [0,59] had 2 tweets\ntweetCounts.getTweetCountsPerFrequency("minute", "tweet3", 0, 60); // return [2,1]; chunk [0,59] had 2 tweets, chunk [60,60] had 1 tweet\ntweetCounts.recordTweet("tweet3", 120); // New tweet "tweet3" at time 120\ntweetCounts.getTweetCountsPerFrequency("hour", "tweet3", 0, 210); // return [4]; chunk [0,210] had 4 tweets\n</pre>\n\n<p> </p>\n<p><strong>Constraints:</strong></p>\n\n<ul>\n\t<li><code>0 <= time, startTime, endTime <= 10<sup>9</sup></code></li>\n\t<li><code>0 <= endTime - startTime <= 10<sup>4</sup></code></li>\n\t<li>There will be at most <code>10<sup>4</sup></code> calls <strong>in total</strong> to <code>recordTweet</code> and <code>getTweetCountsPerFrequency</code>.</li>\n</ul>\n",
|
||
"translatedTitle": "推文计数",
|
||
"translatedContent": "<p>一家社交媒体公司正试图通过分析特定时间段内出现的推文数量来监控其网站上的活动。这些时间段可以根据特定的频率( <strong>每分钟 </strong>、<strong>每小时 </strong>或 <strong>每一天</strong> )划分为更小的 <strong>时间段</strong> 。</p>\n\n<p> </p>\n\n<p>例如,周期 <code>[10,10000]</code> (以 <strong>秒</strong> 为单位)将被划分为以下频率的 <strong>时间块</strong> :</p>\n\n<ul>\n\t<li>每 <strong>分钟</strong> (60秒 块):<meta charset=\"UTF-8\" /> <code>[10,69]</code>, <code>[70,129]</code>, <code>[130,189]</code>, <code>...</code>, <code>[9970,10000]</code></li>\n\t<li>每 <strong>小时</strong> (3600秒 块):<meta charset=\"UTF-8\" /><code>[10,3609]</code>, <code>[3610,7209]</code>, <code>[7210,10000]</code></li>\n\t<li>每 <strong>天</strong> (86400秒 块):<meta charset=\"UTF-8\" /> <code>[10,10000]</code></li>\n</ul>\n\n<p>注意,最后一个块可能比指定频率的块大小更短,并且总是以时间段的结束时间结束(在上面的示例中为 <code>10000</code> )。</p>\n\n<p>设计和实现一个API来帮助公司进行分析。</p>\n\n<p>实现 <code>TweetCounts</code> 类:</p>\n\n<ul>\n\t<li><code>TweetCounts()</code> 初始化 <code>TweetCounts</code> 对象。</li>\n\t<li>存储记录时间的 <code>tweetName</code> (以秒为单位)。</li>\n\t<li><code>List<integer> getTweetCountsPerFrequency(String freq, String tweetName, int startTime, int endTime)</code> 返回一个整数列表,表示给定时间 <code>[startTime, endTime]</code> (单位秒)和频率频率中,每个 <strong>时间块</strong> 中带有 <code>tweetName</code> 的 <code>tweet</code> 的数量。\n\t<ul>\n\t\t<li><code>freq</code> 是 <code>“minute”</code> 、 <code>“hour”</code> 或 <code>“day”</code> 中的一个,分别表示 <strong>每分钟</strong> 、 <strong>每小时</strong> 或 <strong>每一天</strong> 的频率。</li>\n\t</ul>\n\t</li>\n</ul>\n\n<p> </p>\n\n<p><strong>示例:</strong></p>\n\n<pre>\n<strong>输入:</strong>\n[\"TweetCounts\",\"recordTweet\",\"recordTweet\",\"recordTweet\",\"getTweetCountsPerFrequency\",\"getTweetCountsPerFrequency\",\"recordTweet\",\"getTweetCountsPerFrequency\"]\n[[],[\"tweet3\",0],[\"tweet3\",60],[\"tweet3\",10],[\"minute\",\"tweet3\",0,59],[\"minute\",\"tweet3\",0,60],[\"tweet3\",120],[\"hour\",\"tweet3\",0,210]]\n\n<strong>输出:</strong>\n[null,null,null,null,[2],[2,1],null,[4]]\n\n<strong>解释:</strong>\nTweetCounts tweetCounts = new TweetCounts();\ntweetCounts.recordTweet(\"tweet3\", 0);\ntweetCounts.recordTweet(\"tweet3\", 60);\ntweetCounts.recordTweet(\"tweet3\", 10); // \"tweet3\" 发布推文的时间分别是 0, 10 和 60 。\ntweetCounts.getTweetCountsPerFrequency(\"minute\", \"tweet3\", 0, 59); // 返回 [2]。统计频率是每分钟(60 秒),因此只有一个有效时间间隔 [0,60> - > 2 条推文。\ntweetCounts.getTweetCountsPerFrequency(\"minute\", \"tweet3\", 0, 60); // 返回 [2,1]。统计频率是每分钟(60 秒),因此有两个有效时间间隔 <strong>1)</strong> [0,60> - > 2 条推文,和 <strong>2)</strong> [60,61> - > 1 条推文。 \ntweetCounts.recordTweet(\"tweet3\", 120); // \"tweet3\" 发布推文的时间分别是 0, 10, 60 和 120 。\ntweetCounts.getTweetCountsPerFrequency(\"hour\", \"tweet3\", 0, 210); // 返回 [4]。统计频率是每小时(3600 秒),因此只有一个有效时间间隔 [0,211> - > 4 条推文。\n</pre>\n\n<p> </p>\n\n<p><strong>提示:</strong></p>\n\n<ul>\n\t<li><code>0 <= time, startTime, endTime <= 10<sup>9</sup></code></li>\n\t<li><code>0 <= endTime - startTime <= 10<sup>4</sup></code></li>\n\t<li><code>recordTweet</code> 和 <code>getTweetCountsPerFrequency</code>,最多有<meta charset=\"UTF-8\" /> <code>10<sup>4</sup></code> 次操作。</li>\n</ul>\n",
|
||
"isPaidOnly": false,
|
||
"difficulty": "Medium",
|
||
"likes": 34,
|
||
"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": "Design",
|
||
"slug": "design",
|
||
"translatedName": "设计",
|
||
"__typename": "TopicTagNode"
|
||
},
|
||
{
|
||
"name": "Hash Table",
|
||
"slug": "hash-table",
|
||
"translatedName": "哈希表",
|
||
"__typename": "TopicTagNode"
|
||
},
|
||
{
|
||
"name": "Binary Search",
|
||
"slug": "binary-search",
|
||
"translatedName": "二分查找",
|
||
"__typename": "TopicTagNode"
|
||
},
|
||
{
|
||
"name": "Ordered Set",
|
||
"slug": "ordered-set",
|
||
"translatedName": "有序集合",
|
||
"__typename": "TopicTagNode"
|
||
},
|
||
{
|
||
"name": "Sorting",
|
||
"slug": "sorting",
|
||
"translatedName": "排序",
|
||
"__typename": "TopicTagNode"
|
||
}
|
||
],
|
||
"companyTagStats": null,
|
||
"codeSnippets": [
|
||
{
|
||
"lang": "C++",
|
||
"langSlug": "cpp",
|
||
"code": "class TweetCounts {\npublic:\n TweetCounts() {\n\n }\n \n void recordTweet(string tweetName, int time) {\n\n }\n \n vector<int> getTweetCountsPerFrequency(string freq, string tweetName, int startTime, int endTime) {\n\n }\n};\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * TweetCounts* obj = new TweetCounts();\n * obj->recordTweet(tweetName,time);\n * vector<int> param_2 = obj->getTweetCountsPerFrequency(freq,tweetName,startTime,endTime);\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Java",
|
||
"langSlug": "java",
|
||
"code": "class TweetCounts {\n\n public TweetCounts() {\n\n }\n \n public void recordTweet(String tweetName, int time) {\n\n }\n \n public List<Integer> getTweetCountsPerFrequency(String freq, String tweetName, int startTime, int endTime) {\n\n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * TweetCounts obj = new TweetCounts();\n * obj.recordTweet(tweetName,time);\n * List<Integer> param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime);\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Python",
|
||
"langSlug": "python",
|
||
"code": "class TweetCounts(object):\n\n def __init__(self):\n\n\n def recordTweet(self, tweetName, time):\n \"\"\"\n :type tweetName: str\n :type time: int\n :rtype: None\n \"\"\"\n\n\n def getTweetCountsPerFrequency(self, freq, tweetName, startTime, endTime):\n \"\"\"\n :type freq: str\n :type tweetName: str\n :type startTime: int\n :type endTime: int\n :rtype: List[int]\n \"\"\"\n\n\n\n# Your TweetCounts object will be instantiated and called as such:\n# obj = TweetCounts()\n# obj.recordTweet(tweetName,time)\n# param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Python3",
|
||
"langSlug": "python3",
|
||
"code": "class TweetCounts:\n\n def __init__(self):\n\n\n def recordTweet(self, tweetName: str, time: int) -> None:\n\n\n def getTweetCountsPerFrequency(self, freq: str, tweetName: str, startTime: int, endTime: int) -> List[int]:\n\n\n\n# Your TweetCounts object will be instantiated and called as such:\n# obj = TweetCounts()\n# obj.recordTweet(tweetName,time)\n# param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "C",
|
||
"langSlug": "c",
|
||
"code": "\n\n\ntypedef struct {\n \n} TweetCounts;\n\n\nTweetCounts* tweetCountsCreate() {\n \n}\n\nvoid tweetCountsRecordTweet(TweetCounts* obj, char* tweetName, int time) {\n \n}\n\nint* tweetCountsGetTweetCountsPerFrequency(TweetCounts* obj, char* freq, char* tweetName, int startTime, int endTime, int* retSize) {\n \n}\n\nvoid tweetCountsFree(TweetCounts* obj) {\n \n}\n\n/**\n * Your TweetCounts struct will be instantiated and called as such:\n * TweetCounts* obj = tweetCountsCreate();\n * tweetCountsRecordTweet(obj, tweetName, time);\n \n * int* param_2 = tweetCountsGetTweetCountsPerFrequency(obj, freq, tweetName, startTime, endTime, retSize);\n \n * tweetCountsFree(obj);\n*/",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "C#",
|
||
"langSlug": "csharp",
|
||
"code": "public class TweetCounts {\n\n public TweetCounts() {\n\n }\n \n public void RecordTweet(string tweetName, int time) {\n\n }\n \n public IList<int> GetTweetCountsPerFrequency(string freq, string tweetName, int startTime, int endTime) {\n\n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * TweetCounts obj = new TweetCounts();\n * obj.RecordTweet(tweetName,time);\n * IList<int> param_2 = obj.GetTweetCountsPerFrequency(freq,tweetName,startTime,endTime);\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "JavaScript",
|
||
"langSlug": "javascript",
|
||
"code": "\nvar TweetCounts = function() {\n\n};\n\n/** \n * @param {string} tweetName \n * @param {number} time\n * @return {void}\n */\nTweetCounts.prototype.recordTweet = function(tweetName, time) {\n\n};\n\n/** \n * @param {string} freq \n * @param {string} tweetName \n * @param {number} startTime \n * @param {number} endTime\n * @return {number[]}\n */\nTweetCounts.prototype.getTweetCountsPerFrequency = function(freq, tweetName, startTime, endTime) {\n\n};\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * var obj = new TweetCounts()\n * obj.recordTweet(tweetName,time)\n * var param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "TypeScript",
|
||
"langSlug": "typescript",
|
||
"code": "class TweetCounts {\n constructor() {\n \n }\n\n recordTweet(tweetName: string, time: number): void {\n \n }\n\n getTweetCountsPerFrequency(freq: string, tweetName: string, startTime: number, endTime: number): number[] {\n \n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * var obj = new TweetCounts()\n * obj.recordTweet(tweetName,time)\n * var param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "PHP",
|
||
"langSlug": "php",
|
||
"code": "class TweetCounts {\n /**\n */\n function __construct() {\n\n }\n\n /**\n * @param String $tweetName\n * @param Integer $time\n * @return NULL\n */\n function recordTweet($tweetName, $time) {\n\n }\n\n /**\n * @param String $freq\n * @param String $tweetName\n * @param Integer $startTime\n * @param Integer $endTime\n * @return Integer[]\n */\n function getTweetCountsPerFrequency($freq, $tweetName, $startTime, $endTime) {\n\n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * $obj = TweetCounts();\n * $obj->recordTweet($tweetName, $time);\n * $ret_2 = $obj->getTweetCountsPerFrequency($freq, $tweetName, $startTime, $endTime);\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Swift",
|
||
"langSlug": "swift",
|
||
"code": "\nclass TweetCounts {\n\n init() {\n\n }\n \n func recordTweet(_ tweetName: String, _ time: Int) {\n\n }\n \n func getTweetCountsPerFrequency(_ freq: String, _ tweetName: String, _ startTime: Int, _ endTime: Int) -> [Int] {\n\n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * let obj = TweetCounts()\n * obj.recordTweet(tweetName, time)\n * let ret_2: [Int] = obj.getTweetCountsPerFrequency(freq, tweetName, startTime, endTime)\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Kotlin",
|
||
"langSlug": "kotlin",
|
||
"code": "class TweetCounts() {\n\n fun recordTweet(tweetName: String, time: Int) {\n\n }\n\n fun getTweetCountsPerFrequency(freq: String, tweetName: String, startTime: Int, endTime: Int): List<Int> {\n\n }\n\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * var obj = TweetCounts()\n * obj.recordTweet(tweetName,time)\n * var param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Dart",
|
||
"langSlug": "dart",
|
||
"code": "class TweetCounts {\n\n TweetCounts() {\n \n }\n \n void recordTweet(String tweetName, int time) {\n \n }\n \n List<int> getTweetCountsPerFrequency(String freq, String tweetName, int startTime, int endTime) {\n \n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * TweetCounts obj = TweetCounts();\n * obj.recordTweet(tweetName,time);\n * List<int> param2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime);\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Go",
|
||
"langSlug": "golang",
|
||
"code": "type TweetCounts struct {\n\n}\n\n\nfunc Constructor() TweetCounts {\n\n}\n\n\nfunc (this *TweetCounts) RecordTweet(tweetName string, time int) {\n\n}\n\n\nfunc (this *TweetCounts) GetTweetCountsPerFrequency(freq string, tweetName string, startTime int, endTime int) []int {\n\n}\n\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * obj := Constructor();\n * obj.RecordTweet(tweetName,time);\n * param_2 := obj.GetTweetCountsPerFrequency(freq,tweetName,startTime,endTime);\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Ruby",
|
||
"langSlug": "ruby",
|
||
"code": "class TweetCounts\n def initialize()\n\n end\n\n\n=begin\n :type tweet_name: String\n :type time: Integer\n :rtype: Void\n=end\n def record_tweet(tweet_name, time)\n\n end\n\n\n=begin\n :type freq: String\n :type tweet_name: String\n :type start_time: Integer\n :type end_time: Integer\n :rtype: Integer[]\n=end\n def get_tweet_counts_per_frequency(freq, tweet_name, start_time, end_time)\n\n end\n\n\nend\n\n# Your TweetCounts object will be instantiated and called as such:\n# obj = TweetCounts.new()\n# obj.record_tweet(tweet_name, time)\n# param_2 = obj.get_tweet_counts_per_frequency(freq, tweet_name, start_time, end_time)",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Scala",
|
||
"langSlug": "scala",
|
||
"code": "class TweetCounts() {\n\n def recordTweet(tweetName: String, time: Int) {\n\n }\n\n def getTweetCountsPerFrequency(freq: String, tweetName: String, startTime: Int, endTime: Int): List[Int] = {\n\n }\n\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * var obj = new TweetCounts()\n * obj.recordTweet(tweetName,time)\n * var param_2 = obj.getTweetCountsPerFrequency(freq,tweetName,startTime,endTime)\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Rust",
|
||
"langSlug": "rust",
|
||
"code": "struct TweetCounts {\n\n}\n\n\n/**\n * `&self` means the method takes an immutable reference.\n * If you need a mutable reference, change it to `&mut self` instead.\n */\nimpl TweetCounts {\n\n fn new() -> Self {\n\n }\n \n fn record_tweet(&self, tweet_name: String, time: i32) {\n\n }\n \n fn get_tweet_counts_per_frequency(&self, freq: String, tweet_name: String, start_time: i32, end_time: i32) -> Vec<i32> {\n\n }\n}\n\n/**\n * Your TweetCounts object will be instantiated and called as such:\n * let obj = TweetCounts::new();\n * obj.record_tweet(tweetName, time);\n * let ret_2: Vec<i32> = obj.get_tweet_counts_per_frequency(freq, tweetName, startTime, endTime);\n */",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Racket",
|
||
"langSlug": "racket",
|
||
"code": "(define tweet-counts%\n (class object%\n (super-new)\n \n (init-field)\n \n ; record-tweet : string? exact-integer? -> void?\n (define/public (record-tweet tweet-name time)\n )\n ; get-tweet-counts-per-frequency : string? string? exact-integer? exact-integer? -> (listof exact-integer?)\n (define/public (get-tweet-counts-per-frequency freq tweet-name start-time end-time)\n )))\n\n;; Your tweet-counts% object will be instantiated and called as such:\n;; (define obj (new tweet-counts%))\n;; (send obj record-tweet tweet-name time)\n;; (define param_2 (send obj get-tweet-counts-per-frequency freq tweet-name start-time end-time))",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Erlang",
|
||
"langSlug": "erlang",
|
||
"code": "-spec tweet_counts_init_() -> any().\ntweet_counts_init_() ->\n .\n\n-spec tweet_counts_record_tweet(TweetName :: unicode:unicode_binary(), Time :: integer()) -> any().\ntweet_counts_record_tweet(TweetName, Time) ->\n .\n\n-spec tweet_counts_get_tweet_counts_per_frequency(Freq :: unicode:unicode_binary(), TweetName :: unicode:unicode_binary(), StartTime :: integer(), EndTime :: integer()) -> [integer()].\ntweet_counts_get_tweet_counts_per_frequency(Freq, TweetName, StartTime, EndTime) ->\n .\n\n\n%% Your functions will be called as such:\n%% tweet_counts_init_(),\n%% tweet_counts_record_tweet(TweetName, Time),\n%% Param_2 = tweet_counts_get_tweet_counts_per_frequency(Freq, TweetName, StartTime, EndTime),\n\n%% tweet_counts_init_ will be called before every test case, in which you can do some necessary initializations.",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "Elixir",
|
||
"langSlug": "elixir",
|
||
"code": "defmodule TweetCounts do\n @spec init_() :: any\n def init_() do\n \n end\n\n @spec record_tweet(tweet_name :: String.t, time :: integer) :: any\n def record_tweet(tweet_name, time) do\n \n end\n\n @spec get_tweet_counts_per_frequency(freq :: String.t, tweet_name :: String.t, start_time :: integer, end_time :: integer) :: [integer]\n def get_tweet_counts_per_frequency(freq, tweet_name, start_time, end_time) do\n \n end\nend\n\n# Your functions will be called as such:\n# TweetCounts.init_()\n# TweetCounts.record_tweet(tweet_name, time)\n# param_2 = TweetCounts.get_tweet_counts_per_frequency(freq, tweet_name, start_time, end_time)\n\n# TweetCounts.init_ will be called before every test case, in which you can do some necessary initializations.",
|
||
"__typename": "CodeSnippetNode"
|
||
}
|
||
],
|
||
"stats": "{\"totalAccepted\": \"5.7K\", \"totalSubmission\": \"16.1K\", \"totalAcceptedRaw\": 5683, \"totalSubmissionRaw\": 16070, \"acRate\": \"35.4%\"}",
|
||
"hints": [],
|
||
"solution": null,
|
||
"status": null,
|
||
"sampleTestCase": "[\"TweetCounts\",\"recordTweet\",\"recordTweet\",\"recordTweet\",\"getTweetCountsPerFrequency\",\"getTweetCountsPerFrequency\",\"recordTweet\",\"getTweetCountsPerFrequency\"]\n[[],[\"tweet3\",0],[\"tweet3\",60],[\"tweet3\",10],[\"minute\",\"tweet3\",0,59],[\"minute\",\"tweet3\",0,60],[\"tweet3\",120],[\"hour\",\"tweet3\",0,210]]",
|
||
"metaData": "{\n \"classname\": \"TweetCounts\",\n \"constructor\": {\n \"params\": []\n },\n \"methods\": [\n {\n \"params\": [\n {\n \"type\": \"string\",\n \"name\": \"tweetName\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"time\"\n }\n ],\n \"name\": \"recordTweet\",\n \"return\": {\n \"type\": \"void\"\n }\n },\n {\n \"params\": [\n {\n \"type\": \"string\",\n \"name\": \"freq\"\n },\n {\n \"type\": \"string\",\n \"name\": \"tweetName\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"startTime\"\n },\n {\n \"type\": \"integer\",\n \"name\": \"endTime\"\n }\n ],\n \"name\": \"getTweetCountsPerFrequency\",\n \"return\": {\n \"type\": \"list<integer>\"\n }\n }\n ],\n \"return\": {\n \"type\": \"boolean\"\n },\n \"systemdesign\": true\n}",
|
||
"judgerAvailable": true,
|
||
"judgeType": "large",
|
||
"mysqlSchemas": [],
|
||
"enableRunCode": true,
|
||
"envInfo": "{\"cpp\":[\"C++\",\"<p>\\u7248\\u672c\\uff1a<code>clang 11<\\/code> \\u91c7\\u7528\\u6700\\u65b0C++ 20\\u6807\\u51c6\\u3002<\\/p>\\r\\n\\r\\n<p>\\u7f16\\u8bd1\\u65f6\\uff0c\\u5c06\\u4f1a\\u91c7\\u7528<code>-O2<\\/code>\\u7ea7\\u4f18\\u5316\\u3002<a href=\\\"https:\\/\\/github.com\\/google\\/sanitizers\\/wiki\\/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer<\\/a> \\u4e5f\\u88ab\\u5f00\\u542f\\u6765\\u68c0\\u6d4b<code>out-of-bounds<\\/code>\\u548c<code>use-after-free<\\/code>\\u9519\\u8bef\\u3002<\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u4f7f\\u7528\\u65b9\\u4fbf\\uff0c\\u5927\\u90e8\\u5206\\u6807\\u51c6\\u5e93\\u7684\\u5934\\u6587\\u4ef6\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8\\u5bfc\\u5165\\u3002<\\/p>\"],\"java\":[\"Java\",\"<p>\\u7248\\u672c\\uff1a<code>OpenJDK 17<\\/code>\\u3002\\u53ef\\u4ee5\\u4f7f\\u7528Java 8\\u7684\\u7279\\u6027\\u4f8b\\u5982\\uff0clambda expressions \\u548c stream API\\u3002<\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u65b9\\u4fbf\\u8d77\\u89c1\\uff0c\\u5927\\u90e8\\u5206\\u6807\\u51c6\\u5e93\\u7684\\u5934\\u6587\\u4ef6\\u5df2\\u88ab\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n<p>\\u5305\\u542b Pair \\u7c7b: https:\\/\\/docs.oracle.com\\/javase\\/8\\/javafx\\/api\\/javafx\\/util\\/Pair.html <\\/p>\"],\"python\":[\"Python\",\"<p>\\u7248\\u672c\\uff1a <code>Python 2.7.12<\\/code><\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u65b9\\u4fbf\\u8d77\\u89c1\\uff0c\\u5927\\u90e8\\u5206\\u5e38\\u7528\\u5e93\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8 \\u5bfc\\u5165\\uff0c\\u5982\\uff1a<a href=\\\"https:\\/\\/docs.python.org\\/2\\/library\\/array.html\\\" target=\\\"_blank\\\">array<\\/a>, <a href=\\\"https:\\/\\/docs.python.org\\/2\\/library\\/bisect.html\\\" target=\\\"_blank\\\">bisect<\\/a>, <a href=\\\"https:\\/\\/docs.python.org\\/2\\/library\\/collections.html\\\" target=\\\"_blank\\\">collections<\\/a>\\u3002\\u5982\\u679c\\u60a8\\u9700\\u8981\\u4f7f\\u7528\\u5176\\u4ed6\\u5e93\\u51fd\\u6570\\uff0c\\u8bf7\\u81ea\\u884c\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n<p>\\u6ce8\\u610f Python 2.7 <a href=\\\"https:\\/\\/www.python.org\\/dev\\/peps\\/pep-0373\\/\\\" target=\\\"_blank\\\">\\u5c06\\u57282020\\u5e74\\u540e\\u4e0d\\u518d\\u7ef4\\u62a4<\\/a>\\u3002 \\u5982\\u60f3\\u4f7f\\u7528\\u6700\\u65b0\\u7248\\u7684Python\\uff0c\\u8bf7\\u9009\\u62e9Python 3\\u3002<\\/p>\"],\"c\":[\"C\",\"<p>\\u7248\\u672c\\uff1a<code>GCC 8.2<\\/code>\\uff0c\\u91c7\\u7528GNU11\\u6807\\u51c6\\u3002<\\/p>\\r\\n\\r\\n<p>\\u7f16\\u8bd1\\u65f6\\uff0c\\u5c06\\u4f1a\\u91c7\\u7528<code>-O1<\\/code>\\u7ea7\\u4f18\\u5316\\u3002 <a href=\\\"https:\\/\\/github.com\\/google\\/sanitizers\\/wiki\\/AddressSanitizer\\\" target=\\\"_blank\\\">AddressSanitizer<\\/a>\\u4e5f\\u88ab\\u5f00\\u542f\\u6765\\u68c0\\u6d4b<code>out-of-bounds<\\/code>\\u548c<code>use-after-free<\\/code>\\u9519\\u8bef\\u3002<\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u4f7f\\u7528\\u65b9\\u4fbf\\uff0c\\u5927\\u90e8\\u5206\\u6807\\u51c6\\u5e93\\u7684\\u5934\\u6587\\u4ef6\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n<p>\\u5982\\u60f3\\u4f7f\\u7528\\u54c8\\u5e0c\\u8868\\u8fd0\\u7b97, \\u60a8\\u53ef\\u4ee5\\u4f7f\\u7528 <a href=\\\"https:\\/\\/troydhanson.github.io\\/uthash\\/\\\" target=\\\"_blank\\\">uthash<\\/a>\\u3002 \\\"uthash.h\\\"\\u5df2\\u7ecf\\u9ed8\\u8ba4\\u88ab\\u5bfc\\u5165\\u3002\\u8bf7\\u770b\\u5982\\u4e0b\\u793a\\u4f8b:<\\/p>\\r\\n\\r\\n<p><b>1. \\u5f80\\u54c8\\u5e0c\\u8868\\u4e2d\\u6dfb\\u52a0\\u4e00\\u4e2a\\u5bf9\\u8c61\\uff1a<\\/b>\\r\\n<pre>\\r\\nstruct hash_entry {\\r\\n int id; \\/* we'll use this field as the key *\\/\\r\\n char name[10];\\r\\n UT_hash_handle hh; \\/* makes this structure hashable *\\/\\r\\n};\\r\\n\\r\\nstruct hash_entry *users = NULL;\\r\\n\\r\\nvoid add_user(struct hash_entry *s) {\\r\\n HASH_ADD_INT(users, id, s);\\r\\n}\\r\\n<\\/pre>\\r\\n<\\/p>\\r\\n\\r\\n<p><b>2. \\u5728\\u54c8\\u5e0c\\u8868\\u4e2d\\u67e5\\u627e\\u4e00\\u4e2a\\u5bf9\\u8c61\\uff1a<\\/b>\\r\\n<pre>\\r\\nstruct hash_entry *find_user(int user_id) {\\r\\n struct hash_entry *s;\\r\\n HASH_FIND_INT(users, &user_id, s);\\r\\n return s;\\r\\n}\\r\\n<\\/pre>\\r\\n<\\/p>\\r\\n\\r\\n<p><b>3. \\u4ece\\u54c8\\u5e0c\\u8868\\u4e2d\\u5220\\u9664\\u4e00\\u4e2a\\u5bf9\\u8c61\\uff1a<\\/b>\\r\\n<pre>\\r\\nvoid delete_user(struct hash_entry *user) {\\r\\n HASH_DEL(users, user); \\r\\n}\\r\\n<\\/pre>\\r\\n<\\/p>\"],\"csharp\":[\"C#\",\"<p><a href=\\\"https:\\/\\/docs.microsoft.com\\/en-us\\/dotnet\\/csharp\\/whats-new\\/csharp-9\\\" target=\\\"_blank\\\">C# 10<\\/a> \\u8fd0\\u884c\\u5728 .NET 6 \\u4e0a<\\/p>\"],\"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>\"],\"ruby\":[\"Ruby\",\"<p>\\u4f7f\\u7528<code>Ruby 3.1<\\/code>\\u6267\\u884c<\\/p>\\r\\n\\r\\n<p>\\u4e00\\u4e9b\\u5e38\\u7528\\u7684\\u6570\\u636e\\u7ed3\\u6784\\u5df2\\u5728 Algorithms \\u6a21\\u5757\\u4e2d\\u63d0\\u4f9b\\uff1ahttps:\\/\\/www.rubydoc.info\\/github\\/kanwei\\/algorithms\\/Algorithms<\\/p>\"],\"swift\":[\"Swift\",\"<p>\\u7248\\u672c\\uff1a<code>Swift 5.5.2<\\/code><\\/p>\\r\\n\\r\\n<p>\\u6211\\u4eec\\u901a\\u5e38\\u4fdd\\u8bc1\\u66f4\\u65b0\\u5230 <a href=\\\"https:\\/\\/swift.org\\/download\\/\\\" target=\\\"_blank\\\">Apple\\u653e\\u51fa\\u7684\\u6700\\u65b0\\u7248Swift<\\/a>\\u3002\\u5982\\u679c\\u60a8\\u53d1\\u73b0Swift\\u4e0d\\u662f\\u6700\\u65b0\\u7248\\u7684\\uff0c\\u8bf7\\u8054\\u7cfb\\u6211\\u4eec\\uff01\\u6211\\u4eec\\u5c06\\u5c3d\\u5feb\\u66f4\\u65b0\\u3002<\\/p>\"],\"golang\":[\"Go\",\"<p>\\u7248\\u672c\\uff1a<code>Go 1.21<\\/code><\\/p>\\r\\n\\r\\n<p>\\u652f\\u6301 <a href=\\\"https:\\/\\/github.com\\/emirpasic\\/gods\\/tree\\/v1.18.1\\\" target=\\\"_blank\\\">https:\\/\\/godoc.org\\/github.com\\/emirpasic\\/gods@v1.18.1<\\/a> \\u7b2c\\u4e09\\u65b9\\u5e93\\u3002<\\/p>\"],\"python3\":[\"Python3\",\"<p>\\u7248\\u672c\\uff1a<code>Python 3.10<\\/code><\\/p>\\r\\n\\r\\n<p>\\u4e3a\\u4e86\\u65b9\\u4fbf\\u8d77\\u89c1\\uff0c\\u5927\\u90e8\\u5206\\u5e38\\u7528\\u5e93\\u5df2\\u7ecf\\u88ab\\u81ea\\u52a8 \\u5bfc\\u5165\\uff0c\\u5982<a href=\\\"https:\\/\\/docs.python.org\\/3\\/library\\/array.html\\\" target=\\\"_blank\\\">array<\\/a>, <a href=\\\"https:\\/\\/docs.python.org\\/3\\/library\\/bisect.html\\\" target=\\\"_blank\\\">bisect<\\/a>, <a href=\\\"https:\\/\\/docs.python.org\\/3\\/library\\/collections.html\\\" target=\\\"_blank\\\">collections<\\/a>\\u3002 \\u5982\\u679c\\u60a8\\u9700\\u8981\\u4f7f\\u7528\\u5176\\u4ed6\\u5e93\\u51fd\\u6570\\uff0c\\u8bf7\\u81ea\\u884c\\u5bfc\\u5165\\u3002<\\/p>\\r\\n\\r\\n<p>\\u5982\\u9700\\u4f7f\\u7528 Map\\/TreeMap \\u6570\\u636e\\u7ed3\\u6784\\uff0c\\u60a8\\u53ef\\u4f7f\\u7528 <a href=\\\"http:\\/\\/www.grantjenks.com\\/docs\\/sortedcontainers\\/\\\" target=\\\"_blank\\\">sortedcontainers<\\/a> \\u5e93\\u3002<\\/p>\"],\"scala\":[\"Scala\",\"<p>\\u7248\\u672c\\uff1a<code>Scala 2.13<\\/code><\\/p>\"],\"kotlin\":[\"Kotlin\",\"<p>\\u7248\\u672c\\uff1a<code>Kotlin 1.9.0<\\/code><\\/p>\\r\\n\\r\\n<p>\\u6211\\u4eec\\u4f7f\\u7528\\u7684\\u662f JetBrains \\u63d0\\u4f9b\\u7684 experimental compiler\\u3002\\u5982\\u679c\\u60a8\\u8ba4\\u4e3a\\u60a8\\u9047\\u5230\\u4e86\\u7f16\\u8bd1\\u5668\\u76f8\\u5173\\u7684\\u95ee\\u9898\\uff0c\\u8bf7\\u5411\\u6211\\u4eec\\u53cd\\u9988<\\/p>\"],\"rust\":[\"Rust\",\"<p>\\u7248\\u672c\\uff1a<code>rust 1.58.1<\\/code><\\/p>\\r\\n\\r\\n<p>\\u652f\\u6301 crates.io \\u7684 <a href=\\\"https:\\/\\/crates.io\\/crates\\/rand\\\" target=\\\"_blank\\\">rand<\\/a><\\/p>\"],\"php\":[\"PHP\",\"<p><code>PHP 8.1<\\/code>.<\\/p>\\r\\n\\r\\n<p>With bcmath module.<\\/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>\"],\"racket\":[\"Racket\",\"<p><a href=\\\"https:\\/\\/docs.racket-lang.org\\/guide\\/performance.html#%28tech._c%29\\\" target=\\\"_blank\\\">Racket CS<\\/a> v8.3<\\/p>\\r\\n\\r\\n<p>\\u4f7f\\u7528 #lang racket<\\/p>\\r\\n\\r\\n<p>\\u5df2\\u9884\\u5148 (require data\\/gvector data\\/queue data\\/order data\\/heap). \\u82e5\\u9700\\u4f7f\\u7528\\u5176\\u5b83\\u6570\\u636e\\u7ed3\\u6784\\uff0c\\u53ef\\u81ea\\u884c require\\u3002<\\/p>\"],\"erlang\":[\"Erlang\",\"Erlang\\/OTP 24.2\"],\"elixir\":[\"Elixir\",\"Elixir 1.13.0 with Erlang\\/OTP 24.2\"],\"dart\":[\"Dart\",\"<p>Dart 2.17.3<\\/p>\\r\\n\\r\\n<p>\\u60a8\\u7684\\u4ee3\\u7801\\u5c06\\u4f1a\\u88ab\\u4e0d\\u7f16\\u8bd1\\u76f4\\u63a5\\u8fd0\\u884c<\\/p>\"]}",
|
||
"book": null,
|
||
"isSubscribed": false,
|
||
"isDailyQuestion": false,
|
||
"dailyRecordStatus": null,
|
||
"editorType": "CKEDITOR",
|
||
"ugcQuestionId": null,
|
||
"style": "LEETCODE",
|
||
"exampleTestcases": "[\"TweetCounts\",\"recordTweet\",\"recordTweet\",\"recordTweet\",\"getTweetCountsPerFrequency\",\"getTweetCountsPerFrequency\",\"recordTweet\",\"getTweetCountsPerFrequency\"]\n[[],[\"tweet3\",0],[\"tweet3\",60],[\"tweet3\",10],[\"minute\",\"tweet3\",0,59],[\"minute\",\"tweet3\",0,60],[\"tweet3\",120],[\"hour\",\"tweet3\",0,210]]",
|
||
"__typename": "QuestionNode"
|
||
}
|
||
}
|
||
} |