标签:git ase str increase 长度 串匹配 返回 匹配 log
Return?any?permutation?A
?of?[0, 1, ..., N]
?such that for all?i = 0,?..., N-1
:
S[i] == "I"
, then?A[i] < A[i+1]
S[i] == "D"
, then?A[i] > A[i+1]
Example 1:
Input: "IDID"
Output: [0,4,1,3,2]
Example 2:
Input: "III"
Output: [0,1,2,3]
Example 3:
Input: "DDI"
Output: [3,2,0,1]
Note:
1 <= S.length <= 10000
S
?only contains characters?"I"
?or?"D"
.class Solution {
public:
vector<int> diStringMatch(string S) {
vector<int> res;
int n = S.size(), mn = 0, mx = n;
for (char c : S) {
if (c == ‘I‘) res.push_back(mn++);
else res.push_back(mx--);
}
res.push_back(mx);
return res;
}
};
https://github.com/grandyang/leetcode/issues/942
https://leetcode.com/problems/di-string-match/
https://leetcode.com/problems/di-string-match/discuss/194906/C%2B%2B-4-lines-high-low-pointers
https://leetcode.com/problems/di-string-match/discuss/194904/C%2B%2BJavaPython-Straight-Forward
[LeetCode] 942. DI String Match 增减DI字符串匹配
标签:git ase str increase 长度 串匹配 返回 匹配 log
原文地址:https://www.cnblogs.com/grandyang/p/12806476.html