publicstaticintscoreOfString(String s){int num=0;for(int i=1;i<s.length();i++){num+=Math.abs(s.charAt(i)-s.charAt(i-1));}returnnum;} Runtime:1 ms, faster than100.00%of Java online submissions for Score of a String. Memory Usage:42 MB, less than50.00%of Java online submissio...
Score of a String/main.scala Original file line numberDiff line numberDiff line change @@ -0,0 +1,9 @@ object Solution { def scoreOfString(s: String): Int = { var sum: Int = 0 for (i <- 1 to s.length-1) { sum += (s.charAt(i-1) - s.charAt(i)).abs } return sum...
Given a stringsof zeros and ones,return the maximum score after splitting the string into twonon-emptysubstrings(i.e.leftsubstring andrightsubstring). The score after splitting a string is the number ofzerosin theleftsubstring plus the number ofonesin therightsubstring. Example 1: Input:s = ...
Runtime: 16 ms, faster than 94.77% of Python online submissions for Maximum Score After Splitting a String. Memory Usage: 13.4 MB, less than 65.70% of Python online submissions for Maximum Score After Splitting a String. 1 2 原题链接:https://leetcode.com/problems/maximum-score-after-split...
代码# Go packageleetcodefuncscoreOfParentheses(Sstring)int{res,stack,top,temp:=0,[]int{},-1,0for_,s:=rangeS{ifs=='('{stack=append(stack,-1)top++}else{temp=0forstack[top]!=-1{temp+=stack[top]stack=stack[:len(stack)-1]top--}stack=stack[:len(stack)-1]top--iftemp==0{stack...
leetcode 856. Score of Parentheses(括号的分数) Given a balanced parentheses string s, return the score of the string. The score of a balanced parentheses string is based on the following rule: “()” has score 1. AB has score A + B, wher......
【leetcode】1422. Maximum Score After Splitting a String 题目如下: Given a stringsof zeros and ones,return the maximum score after splitting the string into two non-empty substrings(i.e. left substring and right substring). The score after splitting a string is the number of zeros in the ...
https://github.com/grandyang/leetcode/issues/856 类似题目: Valid Parentheses 参考资料: https://leetcode.com/problems/score-of-parentheses/ https://leetcode.com/problems/score-of-parentheses/discuss/141777/C%2B%2BJavaPython-O(1)-Space
LeetCode 32. Longest Valid Parentheses Given astringcontaining just the characters '(' and ')', find the lengthofthe longest valid (well-formed)parenthesessubstring. Example 1: Example 2: 解法一:用栈stack 解法二:动态规划DP 【LeetCode】856. Score of Parentheses 解题报告(Python & C++) ...
The score after splitting a string is the number of zeros in the left substring plus the number of ones in the right substring. Example 1: Input: s = "011101" Output: 5 Explanation: All possible ways of splitting s into two non-empty substrings are: left = "0" and right = "11101...