Quellcode durchsuchen

Adding more problems

master
Lachlan Jacob vor 5 Jahren
Ursprung
Commit
b60b71c90b
9 geänderte Dateien mit 74 neuen und 0 gelöschten Zeilen
  1. 30
    0
      100/main.py
  2. 3
    0
      100/problem.txt
  3. 3
    0
      100/run.sh
  4. 15
    0
      1299/main.py
  5. 3
    0
      1299/problem.txt
  6. 3
    0
      1299/run.sh
  7. 3
    0
      197/main.sql
  8. 11
    0
      197/problem.txt
  9. 3
    0
      197/run.sh

+ 30
- 0
100/main.py Datei anzeigen

@@ -0,0 +1,30 @@
# Definition for a binary tree node.
class TreeNode:
def __init__(self, x):
self.val = x
self.left = None
self.right = None

class Solution:
def isSameTree(self, p, q):
if p == None and q == None:
return True
elif p == None:
return False
elif q == None:
return False
elif p.val != q.val:
return False
else:
return self.isSameTree(p.left, q.left) and self.isSameTree(p.right, q.right)


t1 = TreeNode(1)
t1.left = TreeNode(2)
t1.right = TreeNode(3)
t2 = TreeNode(1)
t2.left = TreeNode(2)
t2.right = TreeNode(3)
s = Solution()
print("Expected: True")
print("Got:", s.isSameTree(t1, t2))

+ 3
- 0
100/problem.txt Datei anzeigen

@@ -0,0 +1,3 @@
Given two binary trees, write a function to check if they are the same or not.

Two binary trees are considered the same if they are structurally identical and the nodes have the same value.

+ 3
- 0
100/run.sh Datei anzeigen

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

python3 main.py

+ 15
- 0
1299/main.py Datei anzeigen

@@ -0,0 +1,15 @@
class Solution:
def replaceElements(self, arr):
res = []
for (ind, n) in enumerate(arr[0:len(arr)-1]):
biggest = arr[ind + 1]
for x in arr[ind + 1:]:
if x > biggest:
biggest = x
res.append(biggest)
res.append(-1)
return res

s = Solution()
print("Expected: [18,6,6,6,1,-1]")
print("Got:", s.replaceElements([17,18,5,4,6,1]))

+ 3
- 0
1299/problem.txt Datei anzeigen

@@ -0,0 +1,3 @@
Given an array arr, replace every element in that array with the greatest element among the elements to its right, and replace the last element with -1.

After doing so, return the array.

+ 3
- 0
1299/run.sh Datei anzeigen

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

python3 main.py

+ 3
- 0
197/main.sql Datei anzeigen

@@ -0,0 +1,3 @@
SELECT w1.Id AS Id FROM Weather w1
JOIN Weather w2 ON DATEDIFF(w1.RecordDate, w2.RecordDate) = 1
WHERE w1.Temperature > w2.Temperature;

+ 11
- 0
197/problem.txt Datei anzeigen

@@ -0,0 +1,11 @@
Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to its previous (yesterday's) dates.

+---------+------------------+------------------+
| Id(INT) | RecordDate(DATE) | Temperature(INT) |
+---------+------------------+------------------+
| 1 | 2015-01-01 | 10 |
| 2 | 2015-01-02 | 25 |
| 3 | 2015-01-03 | 20 |
| 4 | 2015-01-04 | 30 |
+---------+------------------+------------------+


+ 3
- 0
197/run.sh Datei anzeigen

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

echo "Can't be botherd making this into a test"

Laden…
Abbrechen
Speichern