Algorithm:
/** * 1021. Remove Outermost Parentheses * Easy * <p> * 53 * <p> * 42 * <p> * Favorite * <p> * Share * A valid parentheses string is either empty (""), "(" + A + ")", or A + B, where A and B are valid parentheses strings, and + represents string concatenation. For example, "", "()", "(())()", and "(()(()))" are all valid parentheses strings. * <p> * A valid parentheses string S is primitive if it is nonempty, and there does not exist a way to split it into S = A+B, with A and B nonempty valid parentheses strings. * <p> * Given a valid parentheses string S, consider its primitive decomposition: S = P_1 + P_2 + ... + P_k, where P_i are primitive valid parentheses strings. * <p> * Return S after removing the outermost parentheses of every primitive string in the primitive decomposition of S. * <p> * <p> * <p> * Example 1: * <p> * Input: "(()())(())" * Output: "()()()" * Explanation: * The input string is "(()())(())", with primitive decomposition "(()())" + "(())". * After removing outer parentheses of each part, this is "()()" + "()" = "()()()". * Example 2: * <p> * Input: "(()())(())(()(()))" * Output: "()()()()(())" * Explanation: * The input string is "(()())(())(()(()))", with primitive decomposition "(()())" + "(())" + "(()(()))". * After removing outer parentheses of each part, this is "()()" + "()" + "()(())" = "()()()()(())". * Example 3: * <p> * Input: "()()" * Output: "" * Explanation: * The input string is "()()", with primitive decomposition "()" + "()". * After removing outer parentheses of each part, this is "" + "" = "". * <p> * <p> * Note: * <p> * S.length <= 10000 * S[i] is "(" or ")" * S is a valid parentheses string * * @param S * @return */
JAVA:
public static String removeOuterParentheses(String S) { StringBuilder sb = new StringBuilder(); char[] chars = S.toCharArray(); for (int i = 0, sum = 0; i < chars.length; i++) { if ((chars[i] == '(' && sum++ > 0) || (chars[i] == ')' && --sum > 0)) { sb.append(chars[i]); } } return sb.toString(); }
GO:
func main() { removeOuterParentheses("(()())(())(()(()))") } func removeOuterParentheses(S string) string { strings.ToLower(S) var res bytes.Buffer counter := 0 for _, c := range S { if counter != 0 && !(counter == 1 && c == ')') { res.WriteRune(c) } if c == '(' { counter++ } else { counter-- } } return res.String() }
Review:
https://www.bbc.com/news/health-47937405
Sleep myths 'damaging your health'
讲述部分理论睡眠对我们生活的健康和快乐是不利的。比如:睡觉前玩手机,比如睡觉前喝酒,难以入睡时还躺在床上。
每个人应该保证睡眠时间7~8个小时。
Tip:
jpa-oracle 字段映射踩坑
在对应表实体类中,实体类字段userName 翻译过来对应数据库中表字段 user_name.会自动将驼峰式命名字段替换为中间_.
导致启动失败,找不到user_name字段(数据库中的字段为username).
解决办法
加入注解别名
@column(name="数据库对应字段名称")
Share:
一份十分完整的CPU 100%排查优化指南
https://mp.weixin.qq.com/s/BSt-_6q6HqurRe3Kf5qZzQ