Lynn Study Notes

.NET Developer, Open Source Enthusiast

LeetCode 283. Move Zeroes (Easy)

Given an integer array nums, move all 0’s to the end of it while maintaining the relative order of the non-zero elements.

Note that you must do this in-place without making a copy of the array.

Example :

Input: nums = [0,1,0,3,12]
Output: [1,3,12,0,0]

Input: nums = [0]
Output: [0]

Constraints:

  • 1 <= nums.length <= 104
  • -231 <= nums[i] <= 231 - 1

Follow up: Could you minimize the total number of operations done?


LeetCode 451. Sort Characters By Frequency (Medium)

Given a string s, sort it in decreasing order based on the frequency of the characters. The frequency of a character is the number of times it appears in the string.

Return the sorted string. If there are multiple answers, return any of them.

Example:

Input: s = "tree"
Output: "eert"
Explanation: 'e' appears twice while 'r' and 't' both appear once.
So 'e' must appear before both 'r' and 't'. Therefore "eetr" is also a valid answer.

Input: s = "cccaaa"
Output: "aaaccc"
Explanation: Both 'c' and 'a' appear three times, so both "cccaaa" and "aaaccc" are valid answers.
Note that "cacaca" is incorrect, as the same characters must be together.

Input: s = "Aabb"
Output: "bbAa"
Explanation: "bbaA" is also a valid answer, but "Aabb" is incorrect.
Note that 'A' and 'a' are treated as two different characters.

LeetCode 771. Jewels and Stones (Easy)

You’re given strings jewels representing the types of stones that are jewels, and stones representing the stones you have. Each character in stones is a type of stone you have. You want to know how many of the stones you have are also jewels.

Letters are case sensitive, so “a” is considered a different type of stone from “A”.

Example :

Input: jewels = "aA", stones = "aAAbbbb"
Output: 3

Input: jewels = "z", stones = "ZZ"
Output: 0

ADO .NET筆記小結

ADO.NET是在.NET Framework裡負責資料存取的類別庫集,由連線資料來源connected data source(連線模式)以及離線資料模型disconnected data model(離線模式),兩種模式各有優缺點,共通點是一開始都必須建立與資料庫的連線。

在選擇連接資料庫的模式時,必須謹慎考量使用狀況,因為兩種模式的實作方法與適合場合不一樣,日後要更改必須要全部重寫。


LeetCode 15. 3Sum (Medium)

Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.

Notice that the solution set must not contain duplicate triplets.

Example :

Input: nums = [-1,0,1,2,-1,-4]
Output: [[-1,-1,2],[-1,0,1]]

Input: nums = []
Output: []


Input: nums = [0]
Output: []

LeetCode 136. Single Number (Easy)

Given a non-empty array of integers nums, every element appears twice except for one. Find that single one.

You must implement a solution with a linear runtime complexity and use only constant extra space.

Example:

Input: nums = [2,2,1]
Output: 1

Input: [4,1,2,1,2]
Output: 4

LeetCode 70. Climbing Stairs (Easy)

You are climbing a staircase. It takes n steps to reach the top.

Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

Example :

Input: n = 2
Output: 2
Explanation: There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps

Input: n = 3
Output: 3
Explanation: There are three ways to climb to the top.
1. 1 step + 1 step + 1 step
2. 1 step + 2 steps
3. 2 steps + 1 step

LeetCode 20. Valid Parentheses (Easy)

Given a string s containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.

An input string is valid if:

Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order.


LeetCode 1. Two Sum (Easy)

https://leetcode.com/problems/two-sum/ 題目的要求是給予一個int陣列和目標值,回傳目標值是陣列中哪兩個索引中加起來的。

Example :

Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Explanation: Because nums[0] + nums[1] == 9, we return [0, 1].

想了想可以直接用兩個For迴圈暴力解掉,考慮到複雜度的問題這邊改用Dictinary的方式解題,Dictionary是由Key和Value組成,但是Key是不能重複的。


C#檔案壓縮搬移處理

雖然這個Blog是藉由GitHub Pages代管,不過像是md檔和其他資料不是說要復原就復原的,要復原還要經過一段步驟,早上實作了一次實在是搞得頭很昏,找時間在照著教學做一次並把過程記錄下來以備不時之需。

養成備份習慣是很重要的,不然資料不見了去資料救援還不一定能把資料救回來,所以我要讓我這Blog的檔案做個每日備份到雲端裡面。

首先看了一下這資料夾的檔案非常瑣碎,才93M的空間卻有14392個檔案,這樣直接備份到雲端光同步就會耗掉相當大的資源,所以我的想法是把資料夾壓縮起來再備份到雲端就好了。