Pārlūkot izejas kodu

Actually did this yesterday, but thought it would become a numbered problem

master
Lachlan Jacob pirms 5 gadiem
vecāks
revīzija
2082e8ba7b

+ 20
- 0
problems/april-day7/main.py Parādīt failu

@@ -0,0 +1,20 @@
class Solution:
def countElements(self, arr):
hm = dict()
for n in arr:
if n in hm:
hm[n] += 1
else:
hm[n] = 1
count = 0
for key, value in hm.items():
if key + 1 in hm:
count += hm[key]
return count

s = Solution()
print("Expected: 2")
print("Got:", s.countElements([1, 2, 3]))

+ 33
- 0
problems/april-day7/problem.txt Parādīt failu

@@ -0,0 +1,33 @@
Given an integer array arr, count element x such that x + 1 is also in arr.

If there're duplicates in arr, count them seperately.

Example 1:

Input: arr = [1,2,3]
Output: 2
Explanation: 1 and 2 are counted cause 2 and 3 are in arr.

Example 2:

Input: arr = [1,1,3,3,5,5,7,7]
Output: 0
Explanation: No numbers are counted, cause there's no 2, 4, 6, or 8 in arr.

Example 3:

Input: arr = [1,3,2,3,5,0]
Output: 3
Explanation: 0, 1 and 2 are counted cause 1, 2 and 3 are in arr.

Example 4:

Input: arr = [1,1,2,2]
Output: 2
Explanation: Two 1s are counted cause 2 is in arr.


Constraints:

1 <= arr.length <= 1000
0 <= arr[i] <= 1000

+ 3
- 0
problems/april-day7/run.sh Parādīt failu

@@ -0,0 +1,3 @@
#!/bin/bash

python3 main.py

Notiek ielāde…
Atcelt
Saglabāt