goden1010

package
v0.0.0-...-b071cee Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2023 License: GPL-3.0 Imports: 0 Imported by: 0

README

面试题 10.10.数字流的秩

1. 题目描述

假设你正在读取一串整数。每隔一段时间,你希望能找出数字 x 的秩(小于或等于 x 的值的个数)。请实现数据结构和算法来支持这些操作,也就是说:

实现 track(int x) 方法,每读入一个数字都会调用该方法;

实现 getRankOfNumber(int x) 方法,返回小于或等于 x 的值的个数。

注意: 本题相对原题稍作改动

示例:

输入:
["StreamRank", "getRankOfNumber", "track", "getRankOfNumber"]
[[], [1], [0], [0]]
输出:
[null,0,null,1]

提示:

  • x <= 50000
  • trackgetRankOfNumber 方法的调用次数均不超过 2000 次

标签 设计 树状数组 二分查找 数据流

2. 解题

  1. 用数组存储

  2. 树状数组

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StreamRank

type StreamRank struct {
	// contains filtered or unexported fields
}

func Constructor

func Constructor() StreamRank

func (*StreamRank) GetRankOfNumber

func (this *StreamRank) GetRankOfNumber(x int) int

func (*StreamRank) Track

func (this *StreamRank) Track(x int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL