Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

added a java solution to problem 295#39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
sakshijha0610 wants to merge2 commits intoBlankj:master
base:master
Choose a base branch
Loading
fromsakshijha0610:master
Open
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletionssrc/com/blankj/hard/0295
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
class MedianFinder {

List<Double> lst ;

public MedianFinder() {
lst = new ArrayList<>();
}

public void addNum(int num) {

double n = num*1.0;

/* for(int i=0;i<lst.size();i++)
{
if(lst.get(i)>n)
{
lst.add(i,n);
return;
}
} */
lst.add(n);
}

public double findMedian() {

Collections.sort(lst);

int sz= lst.size();
//System.out.println(lst.size());

if(sz%2!=0)
{
return lst.get(sz/2);
}
else
{
return (lst.get(sz/2)+lst.get((sz-1)/2))/2.0;
}

}
}

[8]ページ先頭

©2009-2025 Movatter.jp