| @@ -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)) | |||
| @@ -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. | |||
| @@ -0,0 +1,3 @@ | |||
| #!/bin/bash | |||
| python3 main.py | |||
| @@ -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])) | |||
| @@ -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. | |||
| @@ -0,0 +1,3 @@ | |||
| #!/bin/bash | |||
| python3 main.py | |||
| @@ -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; | |||
| @@ -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 | | |||
| +---------+------------------+------------------+ | |||
| @@ -0,0 +1,3 @@ | |||
| #!/bin/bash | |||
| echo "Can't be botherd making this into a test" | |||