Skip to content

Commit

Permalink
april 5
Browse files Browse the repository at this point in the history
  • Loading branch information
YuriSpiridonov committed Apr 5, 2021
1 parent 04e8b40 commit c8ec42b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions Challenges/2021/April-LeetCoding-Challenge.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ None
|474.|[Ones and Zeroes](https://leetcode.com/problems/ones-and-zeroes/)|~~Python~~|Medium|
|32.|[Longest Valid Parentheses](https://leetcode.com/problems/longest-valid-parentheses/)|~~Python~~|Hard|
|622.|[Design Circular Queue](https://leetcode.com/problems/design-circular-queue/)|[Python](/Medium/622.DesignCircularQueue.py)|Medium|
|775.|[Global and Local Inversions](https://leetcode.com/problems/global-and-local-inversions/)|[Python](/Medium/775.GlobalandLocalInversions.py)|Medium|

## License
The code is open-source and licensed under the [MIT License](/LICENSE).
42 changes: 42 additions & 0 deletions Medium/775.GlobalandLocalInversions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'''
We have some permutation A of [0, 1, ..., N - 1], where
N is the length of A.
The number of (global) inversions is the number of i < j
with 0 <= i < j < N and A[i] > A[j].
The number of local inversions is the number of i with
0 <= i < N and A[i] > A[i+1].
Return true if and only if the number of global inversions
is equal to the number of local inversions.
Example:
Input: A = [1,0,2]
Output: true
Explanation: There is 1 global inversion, and 1 local
inversion.
Example:
Input: A = [1,2,0]
Output: false
Explanation: There are 2 global inversions, and 1 local
inversion.
Note:
- A will be a permutation of [0, 1, ..., A.length - 1].
- A will have length in range [1, 5000].
- The time limit for this problem has been reduced.
'''
#Difficulty: Medium
#

#Runtime: 324 ms, faster than 86.59% of Python3 online submissions for Global and Local Inversions.
#Memory Usage: 15.1 MB, less than 44.06% of Python3 online submissions for Global and Local Inversions.

class Solution:
def isIdealPermutation(self, A: List[int]) -> bool:
for i in range(len(A)):
if abs(A[i] - i) > 1:
return False
return True
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Python solutions of LeetCode problems.
![Language](https://img.shields.io/badge/language-Python-blue.svg)&nbsp;
![Problems Solved](https://img.shields.io/badge/problems%20solved-529%2F1637-orange)&nbsp;
![Problems Solved](https://img.shields.io/badge/problems%20solved-530%2F1637-orange)&nbsp;
[![License](https://img.shields.io/badge/license-MIT-green.svg)](./LICENSE)&nbsp;
![Update](https://img.shields.io/badge/update-Daily-brightgreen.svg)&nbsp;
<br><br>
Expand All @@ -22,7 +22,7 @@ In this repository provided my Python solutions of LeetCode problems.
- [January LeetCoding Challenge](/Challenges/2021/January-LeetCoding-Challenge.md) - 27/31
- [February LeetCoding Challenge](/Challenges/2021/February-LeetCoding-Challenge.md) - 23/28
- [March LeetCoding Challenge](/Challenges/2021/March-LeetCoding-Challenge.md) - 23/31
- [April LeetCoding Challenge](/Challenges/2021/April-LeetCoding-Challenge.md) - 2/30
- [April LeetCoding Challenge](/Challenges/2021/April-LeetCoding-Challenge.md) - 3/30
<br><br>
## Solutions
*P.S. If you like this, please leave me a star.*
Expand Down Expand Up @@ -312,6 +312,7 @@ In this repository provided my Python solutions of LeetCode problems.
|754.|[Reach a Number](https://leetcode.com/problems/reach-a-number/)|[Python](/Medium/754.ReachaNumber.py)|Medium|Math|
|763.|[Partition Labels](https://leetcode.com/problems/partition-labels/)|[Python](/Medium/763.PartitionLabels(bruteforce).py)|Medium|Brute Force - resolve|
|771.|[Jewels and Stones](https://leetcode.com/problems/jewels-and-stones/)|[Python](https://github.com/YuriSpiridonov/LeetCode/blob/master/Easy/771.JewelsandStones.py)|Easy|`while loop`, `for loop` and `list comprehension`|
|775.|[Global and Local Inversions](https://leetcode.com/problems/global-and-local-inversions/)|[Python](/Medium/775.GlobalandLocalInversions.py)|Medium||
|785.|[Is Graph Bipartite?](https://leetcode.com/problems/is-graph-bipartite/)|[Python](/Medium/785.IsGraphBipartite.py)|Medium|Iteratively `BFS`, `stack`, `XOR`|
|804.|[Unique Morse Code Words](https://leetcode.com/problems/unique-morse-code-words/)|[Python](/Easy/804.UniqueMorseCodeWords.py)|Easy|`Dictionary`|
|807.|[Max Increase to Keep City Skyline](https://leetcode.com/problems/max-increase-to-keep-city-skyline/)|[Python](/Medium/807.MaxIncreasetoKeepCitySkyline.py)|Medium||
Expand Down

0 comments on commit c8ec42b

Please sign in to comment.