LeetCode题解(十一)1000-1099,androidstudio播放音频

  • 1051. Height Checker

  • 1078. Occurrences After Bigram

1021. Remove Outermost Parentheses

[Description]

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.

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.

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.

Return S after removing the outermost parentheses of every primitive string in the primitive decomposition of S.

[Example]

Example 1:

Input: “(()())(())”

Output: “()()()”

Explanation:

The input string is “(()())(())”, with primitive decomposition “(()())” + “(())”.

After removing outer parentheses of each part, this is “()()” + “()” = “()()()”.

Example 2:

Input: “(()())(())(()(()))”

Output: “()()()()(())”

Explanation:

The input string is “(()())(())(()(()))”, with primitive decomposition “(()())” + “(())” + “(()(()))”.

After removing outer parentheses of each part, this is “()()” + “()” + “()(())” = “()()()()(())”.

Example 3:

Input: “()()”

Output: “”

Explanation:

The input string is “()()”, with primitive decomposition “()” + “()”.

After removing outer parentheses of each part, this is “” + “” = “”.

Note:

  1. S.length <= 10000

  2. S[i] is “(” or “)”

  3. S is a valid parentheses string

[Answer]

Runtime: 2 ms, faster than 98.06% of Java online submissions for Remove Outermost Parentheses.

Memory Usage: 37.9 MB, less than 28.12% of Java online submissions for Remove Outermost Parentheses.

class Solution {

public String removeOuterParentheses(String S) {

StringBuilder sb = new StringBuilder();

int numL = 0, numR = 0;

for (char c : S.toCharArray()) {

if (c == ‘(’) {

numL++;

if (numL != 1)

sb.append©;

} else {

numR++;

if (numL == numR) {

numL = 0;

numR = 0;

} else {

sb.append©;

}

}

}

return sb.toString();

}

}

Runtime: 19 ms, faster than 16.37% of Java online submissions for Remove Outermost Parentheses.

Memory Usage: 37 MB, less than 94.16% of Java online submissions for Remove Outermost Parentheses.

class Solution {

public String removeOuterParentheses(String S) {

String result = “”;

int open = 0;

for (char c : S.toCharArray()) {

if (c == ‘(’) {

if (open > 0) {

result += “(”;

}

open++;

} else {

if (open > 1) {

result += “)”;

}

open–;

}

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img
img

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
img

图片转存中…(img-ChMZVYG8-1710927553644)]

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
[外链图片转存中…(img-LJqTEUpO-1710927553644)]

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值