Open in app

Sign In

Write

Sign In

jojo lee
jojo lee

1 Follower

Home

About

Jul 26, 2021

[Leetcode]8 : String to Integer (atoi)

Link : https://leetcode.com/problems/string-to-integer-atoi/ Problem : Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer (similar to C/C++'s atoi function). The algorithm for myAtoi(string s) is as follows: 1. Read in and ignore any leading whitespace. 2. Check if the next character (if not already at the end…

Leetcode Solution

2 min read

[Leetcode]8 :  String to Integer (atoi)
[Leetcode]8 :  String to Integer (atoi)
Leetcode Solution

2 min read


Jul 23, 2021

[Leetcode]937 : Reorder Data in Log Files

Link : https://leetcode.com/problems/reorder-data-in-log-files/ Problem : You are given an array of logs. Each log is a space-delimited string of words, where the first word is the identifier. There are two types of logs: Letter-logs: All words (except the identifier) consist of lowercase English letters. Digit-logs: All words (except the identifier)…

Leetcode Solution

1 min read

[Leetcode]937 : Reorder Data in Log Files
[Leetcode]937 : Reorder Data in Log Files
Leetcode Solution

1 min read


Jul 22, 2021

[Leetcode]287 : Find the Duplicate Number

Link : https://leetcode.com/problems/find-the-duplicate-number/ Problem : Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive. There is only one repeated number in nums, return this repeated number. You must solve the problem without modifying the array nums and uses only constant extra space. Thoughts : 1. 用collections.Counter來計算每個數字出現的次數。 2. 如果 count > 1,直接 return。

Leetcode Solution

1 min read

[Leetcode]287 : Find the Duplicate Number
[Leetcode]287 : Find the Duplicate Number
Leetcode Solution

1 min read


Jul 20, 2021

[Leetcode]128: Longest Consecutive Sequence

Link : https://leetcode.com/problems/longest-consecutive-sequence/ Problem : Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must write an algorithm that runs in O(n) time. Thoughts : 1. 先把 nums 放進去 set中,排除重複的數字。 2. 跑 nums迴圈,假設 nums-1 數字有在 set 中,那 nums 就不能當開頭。 3. 如果 nums-1沒有在 set 中,那就可以當開頭,計算值為1,如果 nums+1有在 set中,計算值+1,num+1。 4. 回傳最大的 curr值

Leetcode Solution

1 min read

[Leetcode]128: Longest Consecutive Sequence
[Leetcode]128: Longest Consecutive Sequence
Leetcode Solution

1 min read


Jul 20, 2021

[Leetcode]334: Increasing Triplet Subsequence

Link : https://leetcode.com/problems/increasing-triplet-subsequence/ Problem: Given an integer array nums, return true if there exists a triple of indices (i, j, k) such that i < j < k and nums[i] < nums[j] < nums[k]. If no such indices exists, return false. Thoughts: 1. 直接跑array內的值(nums[i] < nums[j] < nums[k])做比較,i<j<k這個照迴圈跑就可以達成。 2. first, second先設為 infinity,然後比較小的值取代掉 first, second 3. 假設 nums =[2,1,5,0,4,6] num, first, second = [2, 2, inf] num, first, second = [1, 1, inf] num, first, second = [5, 1, 5] num, first, second = [0, 0, 5] num, first, second = [4, 0, 4] num = 6, [0, 4, 6]

Leetcode Solution

1 min read

[Leetcode]334: Increasing Triplet Subsequence
[Leetcode]334: Increasing Triplet Subsequence
Leetcode Solution

1 min read


Jul 19, 2021

[Leetcode]11: Container With Most Water

Link :https://leetcode.com/problems/container-with-most-water/ Problem : Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of the line i is at (i, ai) and (i, 0). Find two lines, which, together with the x-axis forms a container, such that the container contains the most water. Notice that you may not slant the container. 找到最大長方形面積。使用兩個pointer來實作,計算每次的長方形面積大小,將比較矮的邊長往下一個位置移動(盡量保留較大的值)。

Leetcode Medium

1 min read

[Leetcode]11: Container With Most Water
[Leetcode]11: Container With Most Water
Leetcode Medium

1 min read


Jul 15, 2021

[Leetcode]55. Jump Game

Link : https://leetcode.com/problems/jump-game/ Problem : Given an array of non-negative integers nums, you are initially positioned at the first index of the array. Each element in the array represents your maximum jump length at that position. Determine if you are able to reach the last index. 有一個array nums,起始位置在 first index,每一次前進的值為nums[i],試問是否在array結束前來到最後最後一個數上。 …

Leetcode

1 min read

[Leetcode]55. Jump Game
[Leetcode]55. Jump Game
Leetcode

1 min read


Jul 14, 2021

[Leetcode]690: Employee Importance

Link : https://leetcode.com/problems/employee-importance/ Problem : You have a data structure of employee information, which includes the employee’s unique id, their importance value, and their direct subordinates’ id. You are given an array of employees employees where: employees[i].id is the ID of the ith employee. employees[i].importance is the importance value of…

Leetcode Solution

2 min read

[Leetcode]690: Employee Importance
[Leetcode]690: Employee Importance
Leetcode Solution

2 min read


Jul 14, 2021

[Leetcode]119 : Pascal’s Triangle II

Link : https://leetcode.com/problems/pascals-triangle-ii/ Problem : Given an integer rowIndex, return the rowIndexth (0-indexed) row of the Pascal's triangle. In Pascal’s triangle, each number is the sum of the two numbers directly above it as shown: Thoughts : 1. 只 return 該行的結果。 2. 先計算該行會有幾個數字。 (Note : rowIndex從0開始) 3. 每一行的結果都是上一行的兩個數字、兩個數字加起來的。並且每一行的第一個數字都是1。 ex: 第二行為 0, 1, 1, 0 第三行為 0+1, 1+1, 0+1 = 1, 2, 1 (Note:從後面開始加,第四位跟第三位開始加,第三位跟第二位,第二位跟第一位) 如果從前面開始加會變成: 第二行為 0, 1, 1, 0 第三行為 0+1, 1+1, (1+1)+1 = 1, 2, 3 ->會出現問題,所以從後面開始加3. 4. return 結果。

Leetcode Solution

2 min read

[Leetcode]119 : Pascal’s Triangle II
[Leetcode]119 : Pascal’s Triangle II
Leetcode Solution

2 min read


Jul 13, 2021

[Leetcode]118 : Pascal’s Triangle

Link : https://leetcode.com/problems/pascals-triangle/ Problem : Given an integer numRows, return the first numRows of Pascal's triangle.

Leetcode Easy

1 min read

[Leetcode]118 : Pascal’s Triangle
[Leetcode]118 : Pascal’s Triangle
Leetcode Easy

1 min read

jojo lee

jojo lee

1 Follower

Help

Status

Writers

Blog

Careers

Privacy

Terms

About

Text to speech