Algorithm
本周选择的算法题是:Break a Palindrome。
规则
Given a palindromic string of lowercase English letters palindrome
, replace exactly one character with any lowercase English letter so that the resulting string is not a palindrome and that it is the lexicographically smallest one possible.
Return the resulting string. If there is no way to replace a character to make it not a palindrome, return an empty string.
A string a
is lexicographically smaller than a string b
(of the same length) if in the first position where a
and b
differ, a
has a character strictly smaller than the corresponding character in b
. For example, "abcc"
is lexicographically smaller than "abcd"
because the first position they differ is at the fourth character, and 'c'
is smaller than 'd'
.
Example 1:
Input: palindrome = "abccba"
Output: "aaccba"
Explanation: There are many ways to make "abccba" not a palindrome, such as "zbccba", "aaccba", and "abacba".
Of all the ways, "aaccba" is the lexicographically smallest.
Example 2:
Input: palindrome = "a"
Output: ""
Explanation: There is no way to replace a single character to make "a" not a palindrome, so return an empty string.
Example 3:
Input: palindrome = "aa"
Output: "ab"
Example 4:
Input: palindrome = "aba"
Output: "abb"
Constraints:
1 <= palindrome.length <= 1000
palindrome
consists of only lowercase English letters.
Solution
class Solution:
def breakPalindrome(self, palindrome: str) -> str:
length = len(palindrome)
if length == 1: return ""
for i in range(length // 2):
if palindrome[i] != 'a':
return palindrome[:i] + 'a' + palindrome[i+1:]
return palindrome[:-1] + 'b'
Review
How to Avoid Coupling in Microservices Design
服务治理是行业的热门话题,业界还有很多像 Aspecto 这样的工具和平台帮助开发者去治理他们的服务。然而服务治理,特别是数据依赖治理之路很漫长,很多时候为了“效率”和恐惧会选择牺牲设计的完整性,但这无异于杀鸡取卵。
作者在本文分享了很多服务解耦的干货,话题包括数据库共享、代码共享、同步通信、共享测试环境、在集成测试中调用下游服务、过度共享领域数据。
Tip
学习了新的工具: mermaid。
Share
近期对双月目标和落地过程做了个复盘,对个人来说有一些收获:
- 要在方案的各个阶段和协作方做更频繁的沟通,进一步提高过程的透明度,让大家能以不同的形式参与进来
- 目标的结果衡量很重要,需要在目标设立初期就明确好,不能忽视业务发展阶段这个维度
- 涉及多团队的需求,要明确好各团队的接口人,并在有一致认同的目标前提下再行动
- “完成比完美更重要”,用 MVP 去验证价值,过程中快速迭代、持续互动、不断审视
- 前期的准备工作、中期的实施及后期的监控与风险评估同等重要