Description


Description

  1. Open brackets must be closed by the same type of brackets.
  2. Open brackets must be closed in the correct order.

Description


Description

Input: ["flower","flow","flight"]
Output: "fl"
Input: ["dog","racecar","car"]
Output: ""
Explanation: There is no common prefix among the input strings.

Solution

/*Go Approach 1: Horizontal scanning*/
/*Time complexity : O(S), where S is the sum of all characters in all strings.*/
/*Space complexity : O(1). We only used constant extra space. */
func longestCommonPrefix(strs []string) string {
if len(strs) == 0 {
return ""
}
// Assume prefix
prefix := strs[0]
for i := 1; i < len(strs); i++ {
for !strings.HasPrefix(strs[i], prefix) {
prefix = prefix[0:len(prefix)-1]
if len(prefix) == 0 {
return ""
}
}
}
return prefix
}

Description

Input: 121
Output: true
Input: -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. …

Description

Input: 123
Output: 321
Input: -123
Output: -321
Input: 120
Output: 21

Description

Given nums = [2, 7, 11, 15], target =…


by Renée French CC BY 3.0

At First

TL;DR

  • If you want to install…

TAKASHI NARIKAWA

Site Reliablity Engineer in Tokyo. SRE/devops/Go/AWS/Terraform

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store