题目描述
给定一个字符串,要求去掉一个字符,使得剩下的两个字符串按顺序拼接在一起,使得最后得到的字符串字典序最小。返回这个字符串。
样例
- 样例1
输入:“acd”
输出:“ac”
解释:"ac"是字典序最小的 - 样例2
输入:“ozwdtvxuhx”
输出:“owdtvxuhx” - 注意事项
保证字符串长度大于1且小于100000
#代码
public class Solution {
/**
* @param str: the str
* @return: the delete positon
*/
public String deleteString(String str) {
// Write your code here.
String res = null;
int len = str.length();
for (int i = 0; i < len - 1; i++) {
if (str.charAt(i) > str.charAt(i+1)) {
res = str.substring(0,i) + str.substring(i+1,len);
return res;
}
}
res = str.substring(0,len-1);
return res;
}
}