耗子叔ARTS:第二周

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

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值