码迷,mamicode.com
首页 > 其他好文 > 详细

Get average stock price every 10 minutes

时间:2014-10-08 10:22:15      阅读:221      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   for   sp   div   c   on   log   

Write a class that displays average of stock prices for a given stock symbol for the last 10 minutes. We have a service that sends stock updates about 5000 times per second. The structure of the message is :

Message {
long timestamp;
String symbol; // E.g. AAPL
double price;
}

 

Idea: Use a buffer that has the capacity of 5000 * 60 * 10 messages. Then insert all the messages in to this buffer if the buffer has extra capacity. if the buffer is full, remove from the head and insert new messages from the tail. When the get average price is called, we calculate all the messages in this buffer.

 

Get average stock price every 10 minutes

标签:style   blog   color   for   sp   div   c   on   log   

原文地址:http://www.cnblogs.com/leetcode/p/4010400.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!