PIXNET Logo登入

西瓜是肥貓

跳到主文

IG:godeyugo 分享 Share 想法跟一些遇到經歷。

部落格全站分類:圖文創作

  • 相簿
  • 部落格
  • 留言
  • 名片
  • 9月 01 週二 202011:52
  • [ LeetCode ] [ Kotlin ] - 204. Count Primes 難度 ★ (Kotlin速度第一名 )

截圖 2020-09-01 上午11.58.39
先看看題目:
204. Count Primes


Easy



Count the number of prime numbers less than a non-negative number, n.


Example:


Input: 10
Output: 4
Explanation: There are 4 prime numbers less than 10, they are 2, 3, 5, 7.

簡單的說就是找出0 到 n整數以內有幾個質數,這一題我一開始自己寫是速度相當慢的,後來參考了別人的答案豁然開朗,其思路就是不要一個數一個數去徹底檢查,而是想辦法做出範圍內的查表,把範圍內被可以被小數字乘的數先找出來,歸類為非質數,每個數都用同張表去查,會省去相當多的時間,來看看程式碼:



(繼續閱讀...)
文章標籤

Deyu 發表在 痞客邦 留言(0) 人氣(20)

  • 個人分類:LeetCode
▲top
  • 8月 19 週三 202015:28
  • [ LeetCode ] [ Kotlin ] - 202. Happy Number 難度 ★ (Kotlin速度第一名 )

截圖 2020-08-19 下午3.26.17



先看看題目:



202. Happy Number


Easy





Write an algorithm to determine if a number n is "happy".


A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers.


Return True if n is a happy number, and False if not.


Example: 


Input: 19
Output: true
Explanation:
12 + 92 = 82
82 + 22 = 68
62 + 82 = 100
12 + 02 + 02 = 1






(繼續閱讀...)
文章標籤

Deyu 發表在 痞客邦 留言(0) 人氣(2)

  • 個人分類:LeetCode
▲top
  • 8月 18 週二 202018:18
  • [ LeetCode ] [ Kotlin ] - 435. Non-overlapping Intervals 難度 ★★

截圖 2020-08-18 下午6.18.21



先看看題目:

435. Non-overlapping Intervals


Medium





Given a collection of intervals, find the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.




 


Example 1:


Input: [[1,2],[2,3],[3,4],[1,3]]
Output: 1
Explanation: [1,3] can be removed and the rest of intervals are non-overlapping.

Example 2:


Input: [[1,2],[1,2],[1,2]]
Output: 2
Explanation: You need to remove two [1,2] to make the rest of intervals non-overlapping.

Example 3:


Input: [[1,2],[2,3]]
Output: 0
Explanation: You don't need to remove any of the intervals since they're already non-overlapping.

 


Note:



  1. You may assume the interval's end point is always bigger than its start point.

  2. Intervals like [1,2] and [2,3] have borders "touching" but they don't overlap each other.





(繼續閱讀...)
文章標籤

Deyu 發表在 痞客邦 留言(0) 人氣(7)

  • 個人分類:LeetCode
▲top
  • 8月 17 週一 202015:19
  • [登山] 小油坑 → 七星山 → 冷水坑 (幹,假日人有夠多

小油坑
這一次的路線是:
捷運劍潭站 -> 1717 , 108 路公車 -> 小油坑服務站  -> 七星山 -> 冷水坑停車場 -> 捷運士林站。
(繼續閱讀...)
文章標籤

Deyu 發表在 痞客邦 留言(0) 人氣(5)

  • 個人分類:
▲top
  • 6月 15 週一 202022:35
  • [JavaScript] 資料型態比對 - 一些特殊情況

null:通常代表找不到
undefined :通常代表尚未定義
(繼續閱讀...)
文章標籤

Deyu 發表在 痞客邦 留言(0) 人氣(1)

  • 個人分類:NodeJs
▲top
  • 6月 15 週一 202014:42
  • [ LeetCode ] [ JavaScript ] - 1309. Decrypt String from Alphabet to Integer Mapping 難度 ★★

截圖 2020-06-15 下午2.42.58

先看看題目:




1309. Decrypt String from Alphabet to Integer Mapping


Easy





Given a string s formed by digits ('0' - '9') and '#' . We want to map s to English lowercase characters as follows:



  • Characters ('a' to 'i') are represented by ('1' to '9') respectively.

  • Characters ('j' to 'z') are represented by ('10#' to '26#') respectively. 


Return the string formed after mapping.


It's guaranteed that a unique mapping will always exist.


 


Example 1:


Input: s = "10#11#12"
Output: "jkab"
Explanation: "j" -> "10#" , "k" -> "11#" , "a" -> "1" , "b" -> "2".

Example 2:


Input: s = "1326#"
Output: "acz"

Example 3:


Input: s = "25#"
Output: "y"

Example 4:


Input: s = "12345678910#11#12#13#14#15#16#17#18#19#20#21#22#23#24#25#26#"
Output: "abcdefghijklmnopqrstuvwxyz"

 


Constraints:



  • 1 <= s.length <= 1000

  • s[i] only contains digits letters ('0'-'9') and '#' letter.

  • s will be valid string such that mapping is always possible.






(繼續閱讀...)
文章標籤

Deyu 發表在 痞客邦 留言(0) 人氣(16)

  • 個人分類:LeetCode
▲top
  • 6月 14 週日 202023:11
  • [ LeetCode ] [ JavaScript ] - 1342. Number of Steps to Reduce a Number to Zero 難度 ★

截圖 2020-06-14 下午11.36.06

先看看題目:


1342. Number of Steps to Reduce a Number to Zero


Easy





Given a non-negative integer num, return the number of steps to reduce it to zero. If the current number is even, you have to divide it by 2, otherwise, you have to subtract 1 from it.


 


Example 1:


Input: num = 14
Output: 6
Explanation: 
Step 1) 14 is even; divide by 2 and obtain 7. 
Step 2) 7 is odd; subtract 1 and obtain 6.
Step 3) 6 is even; divide by 2 and obtain 3. 
Step 4) 3 is odd; subtract 1 and obtain 2. 
Step 5) 2 is even; divide by 2 and obtain 1. 
Step 6) 1 is odd; subtract 1 and obtain 0.

Example 2:


Input: num = 8
Output: 4
Explanation: 
Step 1) 8 is even; divide by 2 and obtain 4. 
Step 2) 4 is even; divide by 2 and obtain 2. 
Step 3) 2 is even; divide by 2 and obtain 1. 
Step 4) 1 is odd; subtract 1 and obtain 0.

Example 3:


Input: num = 123
Output: 12

 


Constraints:



  • 0 <= num <= 10^6




(繼續閱讀...)
文章標籤

Deyu 發表在 痞客邦 留言(0) 人氣(11)

  • 個人分類:LeetCode
▲top
  • 6月 13 週六 202018:32
  • [ LeetCode ] [ JavaScript ] - 1408. String Matching in an Array 難度 ★

截圖 2020-06-13 下午6.14.53

先看看題目:

1408. String Matching in an Array


Easy





Given an array of string words. Return all strings in words which is substring of another word in any order. 


String words[i] is substring of words[j], if can be obtained removing some characters to left and/or right side of words[j].


 


Example 1:


Input: words = ["mass","as","hero","superhero"]
Output: ["as","hero"]
Explanation: "as" is substring of "mass" and "hero" is substring of "superhero".
["hero","as"] is also a valid answer.

Example 2:


Input: words = ["leetcode","et","code"]
Output: ["et","code"]
Explanation: "et", "code" are substring of "leetcode".

Example 3:


Input: words = ["blue","green","bu"]
Output: []

 


Constraints:



  • 1 <= words.length <= 100

  • 1 <= words[i].length <= 30

  • words[i] contains only lowercase English letters.

  • It's guaranteed that words[i] will be unique.




(繼續閱讀...)
文章標籤

Deyu 發表在 痞客邦 留言(0) 人氣(2)

  • 個人分類:LeetCode
▲top
  • 6月 12 週五 202015:53
  • [ LeetCode ] [ JavaScript ] - 27. Remove Element 難度 ★

截圖 2020-06-12 下午4.03.35

先看看題目:
27. Remove Element
Easy


(繼續閱讀...)
文章標籤

Deyu 發表在 痞客邦 留言(0) 人氣(2)

  • 個人分類:LeetCode
▲top
  • 6月 12 週五 202015:14
  • [ LeetCode ] [ JavaScript ] - 26. Remove Duplicates from Sorted Array 難度 ★

截圖 2020-06-12 下午3.13.03
官網題目敘述:

Given a sorted array nums, remove the duplicates in-place such that each element appear only once 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.


Example 1:


Given nums = [1,1,2],
Your function should return length = 2, with the first two elements of nums being 1 and 2 respectively.
It doesn't matter what you leave beyond the returned length.

Example 2:


Given nums = [0,0,1,1,1,2,2,3,3,4],
Your function should return length = 5, with the first five elements of nums being modified to 0, 1, 2, 3, and 4 respectively.
It doesn't matter what values are set beyond the returned length.

Clarification:


Confused why the returned value is an integer but your answer is an array?


Note that the input array is passed in by reference, which means modification to the input array will be known to the caller as well.


Internally you can think of this:


// nums is passed in by reference. (i.e., without making a copy)
int len = removeDuplicates(nums);
// any modification to nums in your function would be known by the caller.
// using the length returned by your function, it prints the first len elements.
for (int i = 0; i < len; i++) {
    print(nums[i]);
}

(繼續閱讀...)
文章標籤

Deyu 發表在 痞客邦 留言(0) 人氣(11)

  • 個人分類:LeetCode
▲top
12...9»

個人資訊

Deyu
暱稱:
Deyu
分類:
圖文創作
好友:
累積中
地區:

文章分類

toggle 讀書心得 (1)
  • 關於相處 (1)
toggle 廢文 (1)
  • 撩妹 (2)
toggle 程式語言 (5)
  • ReactNative (1)
  • NodeJs (2)
  • 前端 (2)
  • LeetCode (17)
  • Android (37)
toggle 生活紀錄 (4)
  • 運動 (2)
  • [國內]出遊 (1)
  • 西瓜皮 (2)
  • 分享 (1)
  • 未分類文章 (1)

熱門文章

  • (1,439)Android-用ADB指令把App Push進 System App層
  • (1,255)[撩妹] 撩妹語錄
  • (1,243)[Android] 利用adb 指令錄製螢幕影片。
  • (964)[心得] 不知道哪一天會分開,但不是今天
  • (963)Android- 鎖Home鍵。(宣告為桌面App
  • (645)Android-根據檔案名稱找出副檔名
  • (404)NodeJs- Line Echo Bot
  • (268)Android-Toast中顯示圖片
  • (18)[HTML] 基本標籤 from freecodecamp。
  • (17)[RN] ReactNative - 個人筆記。

最新文章

  • [ LeetCode ] [ Kotlin ] - 204. Count Primes 難度 ★ (Kotlin速度第一名 )
  • [ LeetCode ] [ Kotlin ] - 202. Happy Number 難度 ★ (Kotlin速度第一名 )
  • [ LeetCode ] [ Kotlin ] - 435. Non-overlapping Intervals 難度 ★★
  • [登山] 小油坑 → 七星山 → 冷水坑 (幹,假日人有夠多
  • [JavaScript] 資料型態比對 - 一些特殊情況
  • [ LeetCode ] [ JavaScript ] - 1309. Decrypt String from Alphabet to Integer Mapping 難度 ★★
  • [ LeetCode ] [ JavaScript ] - 1342. Number of Steps to Reduce a Number to Zero 難度 ★
  • [ LeetCode ] [ JavaScript ] - 1408. String Matching in an Array 難度 ★
  • [ LeetCode ] [ JavaScript ] - 27. Remove Element 難度 ★
  • [ LeetCode ] [ JavaScript ] - 26. Remove Duplicates from Sorted Array 難度 ★

文章精選

最新留言

  • [24/06/06] 訪客 於文章「[減肥] 30天瘦身計畫...」留言:
    立康的L320多功能理療儀可以刺激神經肌肉反覆收縮,幫助局部...
  • [24/04/17] 訪客 於文章「[減肥] 30天瘦身計畫...」留言:
    想減肥減脂,推薦試試EASY SO課程,每次40分鐘,等於自...
  • [24/03/21] 訪客 於文章「[減肥] 30天瘦身計畫...」留言:
    想減重減脂的話,很推薦試試L320,可以幫助進行有效的被動式...
  • [19/12/17] 訪客 於文章「[健身] 深蹲,蹲舉三大好處,三個重點,...」留言:
    請問有機會與您合作無酬業配合作嗎? 有興趣的話zmwu@a...
  • [18/03/21] lin19990127 於文章「Android- 鎖Home鍵。(宣告為...」留言:
    hi 我手機是2015 samsung G a800iz ...
  • [18/03/15] 17國語言翻譯公司 於文章「[Android] Disable Na...」留言:
    有時出下有問上聲了為麼說如他打並人還子心你不實到。 5...
  • [17/03/10] aabc2002tw 於文章「Android- Copy 檔案跟整個資...」留言:
    我找到原因了~我的路徑少打一個"/",你的方法ˋ真的很實用~...
  • [17/03/09] aabc2002tw 於文章「Android- Copy 檔案跟整個資...」留言:
    使用 GoCopyFolder 到 FileOutStrea...
  • [17/03/07] 初學者 於文章「Android-取得目前所在地的經緯度...」留言:
    我是最近正在尋找地理位置資訊相關文章的初學者,目前僅找到設置...
  • [17/03/07] 初學者 於文章「Android-取得目前所在地的經緯度...」留言:
    您好,您的code僅能取得上一次開啟GPS定位的經緯度資訊,...

動態訂閱

留言板

參觀人氣

  • 本日人氣:
  • 累積人氣: