Skip to content

Commit

Permalink
chore:
Browse files Browse the repository at this point in the history
  • Loading branch information
kimi0230 committed Mar 24, 2024
1 parent ad7e095 commit a5ee629
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions Leetcode/0128.Longest-Consecutive-Sequence/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description: "0128.Longest-Consecutive-Sequence"
license: ""
images: []

tags: [LeetCode, Go, Medium, Longest Consecutive Sequence, Array, Hash Table, Union Find]
tags: [LeetCode, Go, Medium, Longest Consecutive Sequence, Array, Hash Table, Union Find, Amazon, Microsoft, Google, Adobe, Spotify]
categories: [LeetCode]

featuredImage: ""
Expand Down Expand Up @@ -62,8 +62,10 @@ seo:

## 題目

## 題目大意
給定一個未排序的整數數位列 nums ,找出數字連續的最長序列(不要求序列元素在原陣列中連續)的長度。
請你設計並實現時間複雜度為 O(n) 的演演算法解決此問題。

## 題目大意

## 解題思路

Expand Down
4 changes: 2 additions & 2 deletions Leetcode/0128.Longest-Consecutive-Sequence/main.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package longestconsecutivesequence

// 時間複雜 O(), 空間複雜 O()
// 時間複雜 O(n), 空間複雜 O(n)
func longestConsecutive(nums []int) int {
m := make(map[int]struct{}, len(nums))
for _, num := range nums {
m[num] = struct{}{}
}
result := 0
for v := range m {
// 如果沒找到該數字的前一個數字, 則把該數字刀做連續序列的第一個數
// 如果沒找到該數字的前一個數字, 則把該數字當做連續序列的第一個數
if _, ok := m[v-1]; !ok {
length := 1
for _, exit := m[v+length]; exit; _, exit = m[v+length] {
Expand Down
2 changes: 1 addition & 1 deletion Leetcode/0167.Two-Sum-II-Input-Array-Is-Sorted/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description: "0167.Two-Sum-II-Input-Array-Is-Sorted"
license: ""
images: []

tags: [LeetCode, Go, Medium, Two Sum II Input Array Is Sorted]
tags: [LeetCode, Go, Medium, Two Sum II Input Array Is Sorted, Array, Two Pointers, Binary Search]
categories: [LeetCode]

featuredImage: ""
Expand Down

0 comments on commit a5ee629

Please sign in to comment.