当前位置:网站首页>Interview question 10.10 Rank of digital stream
Interview question 10.10 Rank of digital stream
2022-06-29 18:27:00 【Mr Gao】
Interview questions 10.10. Rank of digital stream
Suppose you are reading a string of integers . Every once in a while , You want to find out the numbers x The rank of ( Less than or equal to x The number of values of ). Please implement data structures and algorithms to support these operations , in other words :
Realization track(int x) Method , This method is called every time a number is read in ;
Realization getRankOfNumber(int x) Method , Returns less than or equal to x The number of values of .
Be careful : This question is slightly changed from the original one
Example :
Input :
[“StreamRank”, “getRankOfNumber”, “track”, “getRankOfNumber”]
[[], [1], [0], [0]]
Output :
[null,0,null,1]
This question is very simple , Those who are interested can practice
typedef struct {
int val;
struct StreamRank *next;
} StreamRank;
StreamRank* streamRankCreate() {
StreamRank* s=(StreamRank*)malloc(sizeof(StreamRank));
s->next=NULL;
return s;
}
void streamRankTrack(StreamRank* obj, int x) {
StreamRank* s=(StreamRank*)malloc(sizeof(StreamRank));
s->val=x;
s->next=obj->next;
obj->next=s;
}
int streamRankGetRankOfNumber(StreamRank* obj, int x) {
StreamRank* s=obj->next;
int rank=0;
while(s){
if(s->val<=x){
rank++;
}
s=s->next;
}
return rank;
}
void streamRankFree(StreamRank* obj) {
free(obj);
}
/** * Your StreamRank struct will be instantiated and called as such: * StreamRank* obj = streamRankCreate(); * streamRankTrack(obj, x); * int param_2 = streamRankGetRankOfNumber(obj, x); * streamRankFree(obj); */
边栏推荐
- 6.29模拟赛总结
- 如何在树莓派上使用OAK相机?
- 2022.6.29-----leetcode. five hundred and thirty-five
- Markdown knowledge comes gently
- 《安富莱嵌入式周报》第271期:2022.06.20--2022.06.26
- Software testing - you may not understand the basic theoretical knowledge
- The soft youth under the blessing of devcloud makes education "smart" in the cloud
- Adobe Premiere基础-时间重映射(十)
- MySql存储过程循环的使用分析详解
- [tcapulusdb knowledge base] tcapulusdb system user group introduction
猜你喜欢

QQ如何开通在线客服

JWT login authentication

软件测试——基础理论知识你都不一定看得懂

Spingmvc requests and responses

markdown知识轻轻来袭

Precondition end of script headers or end of script output before headers

美法官裁定,被控掩盖黑客行为的Uber前安全主管必须面对欺诈指控

Request header field xxxx is not allowed by Access-Control-Allow-Headers in preflight response问题

Source code installation mavros

mysql -connector/j驱动下载
随机推荐
JWT登录验证
Adobe Premiere基础-不透明度(蒙版)(十一)
[tcapulusdb knowledge base] tcapulusdb doc acceptance - table creation approval introduction
Proxmox VE Install 7.2
Adobe Premiere foundation - batch material import sequence - variable speed and rewind (recall) - continuous action shot switching - subtitle requirements (13)
[wangdingbei 2020 Qinglong formation]areuserialz
Request header field XXXX is not allowed by access control allow headers in preflight response
通过 hosts文件配置本地域名
kubekey2.2.1 kubernetes1.23.7离线包制作+harbor部暑并上传镜像
小迈科技 X Hologres:高可用的百亿级广告实时数仓建设
Automatic software test - read SMS verification code using SMS transponder and selenium
优雅书写Controller(参数验证+统一异常处理)
idea怎么使用?
Longest XOR path (dfs+01trie)
jdbc_相关代码
《安富莱嵌入式周报》第271期:2022.06.20--2022.06.26
Error building sqlsession problem
Kubekey2.2.1 kubernetes1.23.7 offline package production +harbor Department summer and upload image
Jar包后台启动并输出日志
Shell基本语法--流程控制