Skip to content

4. Median of Two Sorted Arrays #11

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 30, 2021

Conversation

nakhlarafi
Copy link
Contributor

I have added a solution to this problem.

Copy link
Owner

@Tahanima Tahanima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work 🔥 Please resolve the feedbacks I've given and then, your pr will be ready for merge.

class Solution {
public double findMedianSortedArrays(int[] nums1, int[] nums2) {
double median = 0.0;
int n1 = nums1.length;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the code to this:

int m = nums1.length;

in order to keep consistent with the problem description. Also, change in other places where you've used n1.

public double findMedianSortedArrays(int[] nums1, int[] nums2) {
double median = 0.0;
int n1 = nums1.length;
int n2 = nums2.length;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the code to this:

int n = nums2.length;

in order to keep consistent with the problem description. Also, change in other places where you've used n2.

double median = 0.0;
int n1 = nums1.length;
int n2 = nums2.length;
int arr[] = new int[n1 + n2];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide a meaningful name to arr, for example: combined, and change in other places where you've used arr.

int n2 = nums2.length;
int arr[] = new int[n1 + n2];
int i = 0, j = 0;
int k = 0;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please combine the above 2 lines to this:

int i = 0, j = 0, k = 0;

int arr[] = new int[n1 + n2];
int i = 0, j = 0;
int k = 0;
while (i < n1 && j < n2) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep a blank line before while. Try to always separate code blocks with a blank line so, please change in other places where appropriate.

@Tahanima
Copy link
Owner

Great work! 🔥 Thank you so much for your contribution! 😀

@Tahanima Tahanima merged commit 42eaea5 into Tahanima:main Jul 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants