GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — leetcode/code/lc1093.java at master · mJackie/leetcode

Expand file tree

/

lc1093.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
45 lines (45 loc) · 1.38 KB
/

lc1093.java

Copy path

File metadata and controls

45 lines (45 loc) · 1.38 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package code;
/*
* 1093. Statistics from a Large Sample
* 题意:从数组里统计出均值,最大,最小,中位数,众数
* 难度:Medium
* 分类:
* 思路:
* Tips:中位数记住可能是两个数的均值,可能是中间的一个数,用 pos/2 来处理
*/
public class lc1093 {
public double[] sampleStats(int[] count) {
double[] res = new double[5];
res[0] = -1;
res[1] = -1;
int mode_num = 0;
int count_num = 0;
for (int i = 0; i < count.length ; i++) {
if(res[0]==-1 && count[i]>0) res[0] = i;
if(count[i]>0 && i>res[1]) res[1] = i;
res[2] += count[i]*i;
count_num += count[i];
if(count[i]>mode_num) {
res[4] = i;
mode_num = count[i];
}
}
int medium_pos1 = (count_num+1)/2; //中位数
int medium_pos2 = (count_num+2)/2;
count_num = 0;
for (int i = 0; i < count.length ; i++) {
count_num += count[i];
if(medium_pos1>0&&medium_pos1<=count_num) {
res[3]+= i;
medium_pos1 = -1;
}
if(medium_pos2>0&&medium_pos2<=count_num) {
res[3]+= i;
medium_pos2 = -1;
}
}
res[2] = res[2]/count_num;
res[3] = res[3]/2;
return res;
}
}
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.