Skip to content

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

2 participants