Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions chobobdev/14.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 14. Longest Common Prefix
// Write a function to find the longest common prefix string amongst an array of strings.

// If there is no common prefix, return an empty string "".

// Example 1:

// Input: strs = ["flower","flow","flight"]
// Output: "fl"
// Example 2:

// Input: strs = ["dog","racecar","car"]
// Output: ""
// Explanation: There is no common prefix among the input strings.

// Constraints:

// 1 <= strs.length <= 200
// 0 <= strs[i].length <= 200
// strs[i] consists of only lower-case English letters.

func longestCommonPrefix(strs []string) string {
if len(strs) == 0 {
return ""
}
if len(strs) == 1 {
return strs[0]
}
var CommonPrefix string = ""
for i := 0; ; i++ {
for j := 0; j <= len(strs)-2; j++ {
if len(strs[j]) < i || len(strs[j+1]) < i || strs[j][:i] != strs[j+1][:i] {
return CommonPrefix
}
}
CommonPrefix = strs[0][:i]
}
return CommonPrefix

}

// Runtime: 4 ms, faster than 16.53% of Go online submissions for Longest Common Prefix.
// Memory Usage: 2.7 MB, less than 11.79% of Go online submissions for Longest Common Prefix.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 7 additions & 7 deletions chobobdev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ Go lang을 활용해 많은 알고리즘 해결
| # | 시도 날짜 | 문제 이름 | 언어 | 링크 |
| :--: | :--------: | :-------: | :--: |:--------------------------: |
| 1 | 2021-05-20 | 27. Remove Element| Go |[:link:](27.go) |
| 2 | 2021-05-23 | 58 . Length of the last word | Go |[:link:](58.md)|
| 3 | 2021-05-24 | 7. Reverse Integer | Go,JS |[:link:](7.md)|
| 5 | 2021-05-20 | 26.Remove Duplicates from Sorted Array| Go |[:link:](26.md) |
| 6 | 2021-05-29 | 9. Palindrome Number | Go | [:link:](9.md) |
| 7 | 2021-05-31 |69. Sqrt(x) | Go | [:link:](69.md) |
| 8 | 2021-05-31 |796. Rotate String | Go | [:link:](796.md) |

| 2 | 2021-05-23 | 58 . Length of the last word | Go |[:link:](58.go)|
| 3 | 2021-05-24 | 7. Reverse Integer | Go,JS |[:link:](7.go)|
| 5 | 2021-05-20 | 26.Remove Duplicates from Sorted Array| Go |[:link:](26.go) |
| 6 | 2021-05-29 | 9. Palindrome Number | Go | [:link:](9.go) |
| 7 | 2021-05-31 |69. Sqrt(x) | Go | [:link:](69.go) |
| 8 | 2021-05-31 |796. Rotate String | Go | [:link:](796.go) |
| 9 | 2021-09-01 |14. Longest Common Prefix | Go | [:link:](14.go) |

<div align="center">

Expand Down