-
Notifications
You must be signed in to change notification settings - Fork 33
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
Conversation
There was a problem hiding this 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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
Great work! 🔥 Thank you so much for your contribution! 😀 |
I have added a solution to this problem.