Changing Quit-Safari Shortcut

How to avoid accidentally quitting Safari on Mac 3 minute read If you are like me, the tabs situation in the browser gets out of hand quickly once the laptop has been running for more than two days. I am not sure if those articles named "7 Things That Surprised The Scientist" or "10 Things You Would Not Believe That Exists!" are really something one should be reading about?

First Step

I wanted to write on a daily basis for some time, but never did it. It was never going to happen if I did not start at all, due to the fear of mistakes or shitty posts. So here is my first shitty post. As an easy measure, I would probably keep up with the writing by posting my solutions to LeetCode exercises as I recently picked up a habit of solving a puzzle a day.

Add Two Numbers

Add Two Numbers | Medium Here goes nothing; day 1 You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0 itself. Example: Input: (2 -> 4 -> 3) + (5 -> 6 -> 4) Output: 7 -> 0 -> 8 Explanation: 342 + 465 = 807.

Largest Triangle Area

812. Largest Triangle Area | Easy Day 2 post. May revisit in the future to come up with more efficient solution. You have a list of points in the plane. Return the area of the largest triangle that can be formed by any 3 of the points. Example: Input: points = [[0,0],[0,1],[1,0],[0,2],[2,0]] Output: 2 Explanation: The five points are show in the figure below. The red triangle is the largest. Notes: * 3 <= points.

Count Numbers With Unique Digits

357. Count Numbers with Unique Digits | Medium Given a non-negative integer n, count all numbers with unique digits, x, where 0 ≤ x < 10n. Example: Input: 2 Output: 91 Explanation: The answer should be the total numbers in the range of 0 ≤ x < 100, excluding 11,22,33,44,55,66,77,88,99 Accepted 56,389 Submissions 121,655 For recursive solution: Runtime: 60 ms, faster than 14.63% of Python3 online submissions for Count Numbers with Unique Digits.

Peak Index in a Mountain Array

852. Peak Index in a Mountain Array | Easy The solution contained is naive approach and can be improved much better. Problem: Let's call an array A a mountain if the following properties hold: A.length >= 3 There exists some 0 < i < A.length - 1 such that A[0] < A[1] < ... A[i-1] < A[i] > A[i+1] > ... > A[A.length - 1] Given an array that is definitely a mountain, return any i such that A[0] < A[1] < .

Univalued Binary Tree

965. Univalued Binary Tree | Easy Another one. It was an easy problem. Another challenge could be to use the least amount of code? Problem: A binary tree is univalued if every node in the tree has the same value. Return true if and only if the given tree is univalued. Example 1: Input: [1,1,1,1,1,null,1] Output: true Example 2: Input: [2,2,2,5,2] Output: false Note: The number of nodes in the given tree will be in the range [1, 100].

Implement Strstr - revisit it

28. Implement strStr() | Easy This one says it's easy but the answer acceptance rate is rather low. The solution below is rather slow and inefficient. With large inputs LeetCode outputs time exceeded error. Will revisit later. class Solution: def strStr(self, haystack, needle): """ :type haystack: str :type needle: str :rtype: int """ # idea 1 - resursive letter checking # idea 2 - iterative each letter checking with elimination # question - what to return when there is more than one match?

Remove Element

27. Remove Element | Easy Problem: """ Given an array nums and a value val, remove all instances of that value in-place and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. The order of elements can be changed. It doesn't matter what you leave beyond the new length. Example 1: Given nums = [3,2,2,3], val = 3, Your function should return length = 2, with the first two elements of nums being 2.

Remove Duplicates From Sorted Array

26. Remove Duplicates from Sorted Array Since the array was already sorted it was straightforward. Runtime: 108 ms, faster than 42.72% of Python3 online submissions for Remove Duplicates from Sorted Array. class Solution: def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ count = len(nums) delta = 1 for i in range(count-1): while i+delta < len(nums) and nums[i+delta] == nums[i]: delta += 1 count -= 1 if i+delta < len(nums): nums[i+1] = nums[i+delta] return count