// inserting into a string #include <iostream> #include <string> int main () { std::string str="to be question"; std::string str2="the "; std::string str3="or not to be"; std::string::iterator it; // used in the s…
Question 443. String Compression Solution 题目大意:把一个有序数组压缩, 思路:遍历数组 Java实现: public int compress(char[] chars) { if (chars.length == 0) return 0; StringBuilder sb = new StringBuilder(); char cur = chars[0]; int sum = 1; for (int i = 1; i <= chars.length…