Skip to content

Commit 9782217

Browse files
committed
Solution of Missing Numbers and fix solution links for 200-300q
1 parent a7ae969 commit 9782217

File tree

2 files changed

+44
-19
lines changed

2 files changed

+44
-19
lines changed

200-300q/268.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
'''
2+
Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array.
3+
4+
Example 1:
5+
6+
Input: [3,0,1]
7+
Output: 2
8+
Example 2:
9+
10+
Input: [9,6,4,2,3,5,7,0,1]
11+
Output: 8
12+
'''
13+
14+
class Solution(object):
15+
def missingNumber(self, nums):
16+
"""
17+
:type nums: List[int]
18+
:rtype: int
19+
"""
20+
if not nums:
21+
return 0
22+
totalSum, n = sum(nums), len(nums)
23+
expectedSum = (n*(n+1))/2
24+
return expectedSum - totalSum

README.md

+20-19
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,29 @@ Python solution of problems from [LeetCode](https://leetcode.com/).
2020
|315|[Count of Smaller Numbers After Self](https://leetcode.com/problems/count-of-smaller-numbers-after-self/) | [Python](./300-400q/315.py)|Hard|
2121

2222

23-
##### [Problems 200-300](./200-300/)
23+
##### [Problems 200-300q](./200-300q/)
2424
| # | Title | Solution | Difficulty |
2525
|---| ----- | -------- | ---------- |
26-
|300|[Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence/) | [Python](./200-300/300.py)|Medium|
27-
|295|[Find Median from Data Stream](https://leetcode.com/problems/find-median-from-data-stream/) | [Python](./200-300/295.py)|Hard|
28-
|289|[Game of Life](https://leetcode.com/problems/game-of-life) | [Python](/200-300/289.py)|Medium|
29-
|287|[Find the Duplicate Number](https://leetcode.com/problems/find-the-duplicate-number/) | [Python](./200-300/287.py)|Hard|
30-
|279|[Perfect Squares](https://leetcode.com/problems/perfect-squares/) | [Python](./200-300/279.py)|Medium|
26+
|300|[Longest Increasing Subsequence](https://leetcode.com/problems/longest-increasing-subsequence/) | [Python](./200-300q/300.py)|Medium|
27+
|295|[Find Median from Data Stream](https://leetcode.com/problems/find-median-from-data-stream/) | [Python](./200-300q/295.py)|Hard|
28+
|289|[Game of Life](https://leetcode.com/problems/game-of-life) | [Python](/200-300q/289.py)|Medium|
29+
|287|[Find the Duplicate Number](https://leetcode.com/problems/find-the-duplicate-number/) | [Python](./200-300q/287.py)|Hard|
30+
|279|[Perfect Squares](https://leetcode.com/problems/perfect-squares/) | [Python](./200-300q/279.py)|Medium|
31+
|268|[Missing Number](https://leetcode.com/problems/missing-number)|[Python](./200-300q/268.py)|Easy|
3132
|253|[Meeting Rooms II](https://leetcode.com/problems/meeting-rooms-ii) | [Python](./200-300q/253.py)|Medium|
32-
|240|[Search a 2D Matrix II](https://leetcode.com/problems/search-a-2d-matrix-ii/)|[Python](./200-300/240.py)|Medium|
33-
|239|[Sliding Window Maximum](https://leetcode.com/problems/sliding-window-maximum/)| [Python](./200-300/239.py)|Hard|
34-
|238|[Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/)| [Python](./200-300/238.py)|Medium|
35-
|236|[Lowest Common Ancestor of a Binary Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/)| [Python](./200-300/236.py)|Medium|
36-
|234|[Palindrome Linked List](https://leetcode.com/problems/palindrome-linked-list/)| [Python](./200-300/234.py)|Easy|
37-
|230|[Kth Smallest Element in a BST](https://leetcode.com/problems/kth-smallest-element-in-a-bst/)| [Python](./200-300/230.py)|Medium|
38-
|215|[Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array/)| [Python](./200-300/215.py)|Medium|
39-
|210|[Course Schedule II](https://leetcode.com/problems/course-schedule-ii/)| [Python](./200-300/210.py)|Medium|
40-
|208|[Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree/)| [Python](./200-300/208.py)|Medium|
41-
|207|[Course Schedule](https://leetcode.com/problems/course-schedule/)| [Python](./200-300/207.py)|Medium|
42-
|206|[Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/)| [Python](./200-300/206.py)|Easy|
43-
|203|[Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements/)| [Python](./200-300/203.py)|Easy|
44-
|200|[Number of Islands](https://leetcode.com/problems/number-of-islands/)| [Python](./200-300/200.py)|Medium|
33+
|240|[Search a 2D Matrix II](https://leetcode.com/problems/search-a-2d-matrix-ii/)|[Python](./200-300q/240.py)|Medium|
34+
|239|[Sliding Window Maximum](https://leetcode.com/problems/sliding-window-maximum/)| [Python](./200-300q/239.py)|Hard|
35+
|238|[Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/)| [Python](./200-300q/238.py)|Medium|
36+
|236|[Lowest Common Ancestor of a Binary Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/)| [Python](./200-300q/236.py)|Medium|
37+
|234|[Palindrome Linked List](https://leetcode.com/problems/palindrome-linked-list/)| [Python](./200-300q/234.py)|Easy|
38+
|230|[Kth Smallest Element in a BST](https://leetcode.com/problems/kth-smallest-element-in-a-bst/)| [Python](./200-300q/230.py)|Medium|
39+
|215|[Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array/)| [Python](./200-300q/215.py)|Medium|
40+
|210|[Course Schedule II](https://leetcode.com/problems/course-schedule-ii/)| [Python](./200-300q/210.py)|Medium|
41+
|208|[Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree/)| [Python](./200-300q/208.py)|Medium|
42+
|207|[Course Schedule](https://leetcode.com/problems/course-schedule/)| [Python](./200-300q/207.py)|Medium|
43+
|206|[Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/)| [Python](./200-300q/206.py)|Easy|
44+
|203|[Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements/)| [Python](./200-300q/203.py)|Easy|
45+
|200|[Number of Islands](https://leetcode.com/problems/number-of-islands/)| [Python](./200-300q/200.py)|Medium|
4546

4647

4748
##### [Problems 100-200](./100-200q/)

0 commit comments

Comments
 (0)