字串中的第一個唯一字元(First Unique Character in a String)
字串中的第一個唯一字元(First Unique Character in a String)虛擬碼function bubble_sort (array, length) { var i, j; for(i from 0 to length-1){ let com_a = nums[i]; for(j from i+1 to length-1){ if (array[j] === com_a) true } } false}
解題387. First Unique Character in a String
題目說明給定一個字串,找到其中的第一個非重複字元並返回其索引。如果不存在,則傳回 。s-1
解法第一種Javascript
/** * @param {string} s * @return {number} */const firstUniqChar = (s) ...
1741. Find Total Time Spent by Each Employee
1741. Find Total Time Spent by Each EmployeeFind Total Time Spent by Each Employee
透過leetcode 1741Find Total Time Spent by Each Employee來練習
使用table
(emp_id, event_day, in_time) 是這個表的主鍵。該表顯示了員工在辦公室的進出。event_day 是該事件發生的日期,in_time 是員工進入辦公室的分鐘,out_time 是他們離開辦公室的分鐘。in_time 和 out_time 介於 1 和 1440 之間。保證同一天沒有兩個事件在時間上相交,並且 in_time < out_time。
題目說明:編寫 SQL 查詢以計算每個員工每天在辦公室花費的總時間(以分鐘為單位)。請注意,在一天內,員工可以多次進入和離開。在辦公室單次進入所花費的時間是。out_time - in_time
按任意順序返回結果表。
查詢結果格式如下例所示。
解題:以下為第一個解法
先將in_time & out_time ...
包含重複項(Contains Duplicate)
包含重複項(Contains Duplicate)虛擬碼function bubble_sort (array, length) { var i, j; for(i from 0 to length-1){ let com_a = nums[i]; for(j from i+1 to length-1){ if (array[j] === com_a) true } } false}
解題217. Contains Duplicate
題目說明給定一個整數陣列,returnif 任何值在陣列中至少出現兩次,returnif 每個元素都是不同的。就是:給你一個array, 問你這個arrary有沒有重複的元素
解法第一種Javascript
/** * @param {number[]} nums * @return {boolean} */var containsDup ...
Linux Test
Linux TestLinuxQ1. To mount a drive by its ID, what command would you use first to retrieve it?
[ ] df -h
[ ] listid
[ ] ls -l
[x] blkid
Q2. Linux file access control lists (ACLs) are _.
[x] discretionary access control system permissions layered over standard Linux permissions
[ ] mandatory access control system permissions layered over standard Linux permissions
[ ] a type of firewall for Linux
[ ] the same as standard Linux permissions
Q3. When using iproute2, how do you show routing inform ...
兩個陣列的交集(Intersection of Two Arrays)
兩個陣列的交集(Intersection of Two Arrays)虛擬碼沒空寫
解題350. Intersection of Two Arrays II
題目說明輸入2個陣列nums1和nums2,求這2個陣列有交集的元素。比如範例輸入的nums1 = [1,2,2,1], nums2 = [2,2],元素有2個2都出現,所以要回傳[2, 2]。
解法對此2個陣列都從小到大排序,建立兩個指標i和j各自從nums1和nums2的最小值往上比對:
如果目前指標指向的值一樣,代表是交集的元素,加入答案,i和j都遞增如果目前指標指向的值nums1[i] > nums2[j],代表nums2更後面的值要拿來與nums1比對,所以只有j遞增如果目前指標指向的值nums1[i] < nums2[j],代表nums1更後面的值要拿來與nums2比對,所以只有i遞增最終i和j有超過nums1/nums2的長度就結束。Javascript
/** * @param {number[]} nums * @return {boolean} */var ...
175. Combine Two Tables
175. Combine Two Tables(資訊來自於leetcode 175 Combine Two Tables)
合併兩個表編寫 SQL 查詢以報告 Person 表中每個人的名字、姓氏、城市和州。如果地址表中不存在 personId 的地址,則改為報告 null。
題目:地址表中沒有 personId = 1 的地址,所以我們在他們的城市和州返回 null。addressId = 1 包含有關 personId = 2 的地址的信息。
解題方式:select M.firstName,M.lastName,A.city,A.statefrom Person Mleft outer join Address A on A.personId = M.personId
解題解析:運用outer join 來把兩個table相加,而沒有城市或是州的資料則會傳回NULL
Java Test
Java TestJavaQ1. Given the string “strawberries” saved in a variable called fruit, what would fruit.substring(2, 5) return?
[ ] rawb
[x] raw
[ ] awb
[ ] traw
Reasoning: The substring method is accepting two arguments.
The first argument being the index to start(includes that char at 2)
and the second the index of the string to end the substring(excludes the char at 5).
Strings in Java are like arrays of chars.
Therefore, the method will return “raw” as those are the chars in indexes 2,3, and 4 ...
重塑矩陣(Reshape the Matrix)
重塑矩陣(Reshape the Matrix)虛擬碼
解題566. Reshape the Matrix
題目說明在 MATLAB 中,有一個方便的函數稱為,它可以將矩陣重塑為具有不同大小的新矩陣,以保留其原始數據。reshapem x nr x c您將獲得一個矩陣和兩個整數,並表示所需重塑矩陣的行數和列數。m x nmatrc重塑后的矩陣應以與原始矩陣相同的行遍歷順序填充原始矩陣的所有元素。如果給定參數的操作是可能的且合法的,則輸出新的重塑矩陣;否則,輸出原始矩陣。reshape
Constraints:
m == mat.length
n == mat[i].length
1 <= m, n <= 100
-1000 <= mat[i][j] <= 1000
1 <= r, c <= 300
解法第一種Javascript
/** * @param {number[][]} mat * @param {number} r * @param {number} c * @return ...
1693. Daily Leads and Partners
1693. Daily Leads and Partners(資訊來自於leetcode 1693 Daily Leads and Partners)
每日線索和合作夥伴編寫一個 SQL 查詢,對於每個date_idand make_name,返回不重複 lead_id和不重複 partner_id的數量。
解題方式:SELECT date_id, make_name, count(distinct lead_id) unique_leads, count(distinct partner_id) unique_partners from DailySales group by date_id,make_name
解題解析:利用sql的distinct的關鍵字來過濾重複出現的紀錄值,這樣我們就可以取得題目所需要的不重複值
Node.js Test
Node.js TestNode.jsQ1. When a javaScript function is invoked (called) in Node, where is a new frame placed?
[x] the call stack
[ ] the event loop
[ ] the poll phase
[ ] the events queue
Explanation: From javascripttutorial: reference
Q2. Which of the following is a core module in Node?
[ ] webpack
[x] crypto
[ ] request
[ ] chalk
Explanation: From flaviocopes docs: reference
Q3. Which of the following Buffer class methods returns an uninitialized buffer?
[x] allocUnsafe
[ ] concat
[ ] from
[ ] ...


