I use python in the work, so when I see this question, I just do what I will do during work:
Use the Python attribute to add list and use the built-in method to sort it.
Then the answer is clear.
def findMedianSortedArrays(self, nums1, nums2): """ :type nums1: List[int] :type nums2: List[int] :rtype: float """ nums = nums1 + nums2 nums.sort() length = len(nums1) + len(nums2) if length%2 == 0: return (nums[length/2 - 1] + nums[length/2])/2.0 else: return nums[length/2]
2080 / 2080 test cases passed.
Runtime: 82 ms
Submitted: 0 minutes ago
So at work, when your boss tells you it should be O(log(m+n)), you will instead do Θ(m+n)? And you think that's fun? Are you not worried about getting fired?
You are definitely right, this is wrong answer.
While I'm saying at work, I was meant to use as much as built in functions as possible. While I'm saying it's fun, I mean it's just for fun.
Please don't relate this to my work and my boss :(
I think the test cases are lacking for this which is why your solution passes the test cases. also your solution might actually be O(nlogn), although I am not sure.
I do know what you mean when you say "at work". We are not constantly thinking about efficiency with every little piece of code we write, so we often write anything that's logically accurate and worry about optimization when necessary.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.