0%

Leetcode 總結

lc-2022

雖然在2021年暑假的這段時間有刷過一整子大概有50道題左右,但是2021年9月到12月在忙畢業專題因此就停止了。直到我12月份去找投實習MataApp 的全棧實習生時,公司給我發來了一份OA或叫面試題並要求在2小時內完成。當時就很激動的便開始寫了(實習問的都有多難),結果都的是算法題(當時一臉懵逼)。最後我花了將近5個小時的時間才完成(超時),收到了深深的打擊(收到了感謝信),也下定了決心2022年好好認真刷題。

這篇文章主要是講述如何在AWS雲服務中部署Kubernetes集群

首先,我們需要準備使用一下工具進行設置

  • KOps - 一個能讓我們輕鬆無痛部署Kubernetes到任何雲服務的工具,可以想象為集群的kubectl
  • AWS IAM - 申請一個能讓Kops存取權限的賬號
  • AWS S3 Bucket - 用來作為存取Kubernets資料的資料庫
  • AWS Route53 - 用於使用自定義Domain Name 並連接到Master Node中
  • GoDady - 作為DNS 服務供應商

前置工作

在電腦中安裝KOps工具用於幫助我們部署集群

想要了解更多關於KOps的讀者,可以參閱 kOps-Kubernetes Operations

Movie App - Frontend
Movie App - Backend

client

簡介

開發這個App的目的主要是為了解決在搜尋電影OTT資源以及電影內容討論分散在多個不同平台等問題,如:搜尋到的資源是無效/不合法的,花費大量時間在搜尋上等等…。因此這個App主要分成2個組成部分,分別是電影資訊搜尋獲取OTT資源,並整合不同OTT平台的電影資源,供用戶選擇合法資源,並過濾無效資源以及電影分享社群,供用戶在觀看完電影後,直接在App中發佈相關文章以分享給其他用戶,而無需在不同平台發佈。

今日為2022年11月13日(週日) - Leetcode 週賽第319場

目前參加週賽主要的目的是學習跟訓練,所有當前主要focus在解Easy 跟 Medium的題目,Hard的題目暫且先跳過了

週賽題目如下:

  1. Convert the Temperature - Easy
  2. Number of Subarrays With LCM Equal to K - Medium
  3. Minimum Number of Operations to Sort a Binary Tree by Level - Medium

Convert the Temperature - Easy

You are given a non-negative floating point number rounded to two decimal places celsius, that denotes the temperature in Celsius.

LeetCode 718 - Maximum Length of Repeated Subarray

Given two integer arrays ``nums1andnums2`, return the maximum length of a subarray that appears in both arrays.

1
2
3
Input: nums1 = [1,2,3,2,1], nums2 = [3,2,1,4,7]
Output: 3
Explanation: The repeated subarray with maximum length is [3,2,1].
1
2
Input: nums1 = [0,0,0,0,0], nums2 = [0,0,0,0,0]
Output: 5

How can we solve this problem?

這題要我們找出2個array中最長的相同subarray。這題有點類似於 最長公共子序列 ,但是不同的是子序列不一樣的連續的,而subarray是必須要連續的。哪我們只需要改寫一下最長公共子序列,我們只需要更新相等的元素即可。其餘的都不需要關心。

LeetCode 42 - Trapping Rain Water

Given a list paths of directory info, including the directory path, and all the files with contents in this directory, return all the duplicate files in the file system in terms of their paths. You may return the answer in any order.

A group of duplicate files consists of at least two files that have the same content.

A single directory info string in the input list has the following format:

今天是我第一次參加Leetcode 雙週賽,所以想記錄一下今天的競賽題目。希望能透過博客來記錄自己的競賽狀況。

本週AC題數為:4/4

題目

2413. Smallest Even Multiple(EASY) - AC

Given a positive integer n, return the smallest positive integer that is a multiple of both 2 and n.

LeetCode 42 - Trapping Rain Water

Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it can trap after raining. example

1
2
3
Input: height = [0,1,0,2,1,0,1,3,2,1,2,1]
Output: 6
Explanation: The above elevation map (black section) is represented by array [0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped.
1
2
Input: height = [4,2,0,3,2,5]
Output: 9

How can we solve this problem?

這題是給定一個array代表著高度,問我們一共可以裝多少水。這題的解題思路,假設當前是i,那我當前這個i是否可以裝水呢?我們是是不是要知道i的左手邊的最高的柱子(x)和最右手邊的最高的柱子(y),那跟柱子比較矮而且是不是大於現在這個i。假設IFF x < y && x > i,哪i可以裝的水就會是x - i那麼多。所以說,我們必須要知道當前i的左邊最高和i的右邊最高是多少。哪要怎麼做呢?我們可以透過預處理的方式,預先計算左手邊(i之前)最大值以及右手邊(i之後)的最大值,然後在根據以上的方法即可解出答案。

LeetCode 336 - Palindrome Pairs

Given a list of unique words, return all the pairs of the distinct indices (i, j) in the given list, so that the concatenation of the two words words[i] + words[j] is a palindrome.

example

1
2
3
Input: words = ["abcd","dcba","lls","s","sssll"]
Output: [[0,1],[1,0],[3,2],[2,4]]
Explanation: The palindromes are ["dcbaabcd","abcddcba","slls","llssssll"]
1
2
3
Input: words = ["bat","tab","cat"]
Output: [[0,1],[1,0]]
Explanation: The palindromes are ["battab","tabbat"]

How can we solve this problem?

在解這題之前我們先要知道有哪些情況是成立Palindrome。