当前位置:网站首页>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); */
边栏推荐
- How do I add SmartArt to slides in PowerPoint?
- Image migration and data migration synchronization of old and new servers with different Alibaba cloud accounts
- 踩坑记:JSON.parse和JSON.stringify
- Markdown common fonts
- MySql存储过程循环的使用分析详解
- 【TcaplusDB知识库】TcaplusDB系统用户组介绍
- Shell basic syntax -- process control
- Sd6.24 summary of intensive training
- Sd6.22 summary of intensive training
- mysql — 清空表中数据
猜你喜欢

Adobe Premiere foundation - opacity (mixed mode) (XII)

报错Failed to allocate graph: MYRIAD device is not opened.

Xiaobai yuesai 51 supplement e g f

Adobe Premiere Basics - common video effects (cropping, black and white, clip speed, mirroring, lens halo) (XV)

How to use idea?

Anaconda安装并配置jupyter notebook远程

NVIDIA installs the latest graphics card driver

Request header field XXXX is not allowed by access control allow headers in preflight response
Detailed analysis on the use of MySQL stored procedure loop

Request header field xxxx is not allowed by Access-Control-Allow-Headers in preflight response问题
随机推荐
Adobe Premiere Basics - general operations for editing material files (offline files, replacing materials, material labels and grouping, material enabling, convenient adjustment of opacity, project pa
Adobe Premiere基础-声音调整(音量矫正,降噪,电话音,音高换挡器,参数均衡器)(十八)
Proxmox VE Install 7.2
C comparison of the performance of dapper efcore sqlsugar FreeSQL hisql sqlserver, an ORM framework at home and abroad
【网络是怎么连接的】第三章 探索集线器,交换机和路由器
Markdown knowledge comes gently
美法官裁定,被控掩盖黑客行为的Uber前安全主管必须面对欺诈指控
行程卡“摘星”热搜第一!刺激旅游产品搜索量齐上涨
Adobe Premiere基础-编辑素材文件常规操作(脱机文件,替换素材,素材标签和编组,素材启用,便捷调节不透明度,项目打包)(十七)
数据分析--时间序列预测
面试题 10.10. 数字流的秩
Adobe Premiere基础-不透明度(混合模式)(十二)
How QQ opens online customer service
PostgreSQL database system table
SD6.22集训总结
报错[warning] Neural network inference was performed on socket ‘RGB’, depth frame is aligned to socket
3H proficient in opencv (VII) - color detection
Configure the local domain name through the hosts file
Codeworks 5 questions per day (1700 for each) - the next day
Shell basic syntax -- process control