Open Zheaoli opened 2 years ago
package main
/*
* @lc app=leetcode.cn id=944 lang=golang
*
* [944] 删列造序
*/
// @lc code=start
func minDeletionSize(strs []string) int {
res := 0
n := len(strs[0])
m := len(strs)
for i := 0; i < n; i++ {
for j := 1; j < m; j++ {
if strs[j][i] >= strs[j-1][i] {
continue
}
res++
break
}
}
return res
}
// func main() {
// fmt.Println(minDeletionSize([]string{"zyx", "wvu", "tsr"}))
// }
// @lc code=end
微信id: 而我撑伞 来自 vscode 插件
class Solution {
public boolean oneEditAway(String first, String second) {
int n = first.length() - second.length();
if (n < -1 || n > 1) {
return false;
}
int cnt = 1;
for (int i = 0, j = 0; i < first.length() && j < second.length(); i++, j++) {
if (first.charAt(i) != second.charAt(j)) {
if (n == 1) {
//first删除字符
j--;
} else if (n == -1) {
//second删除字符
i--;
}
cnt--;
//只允许一次编辑操作
if (cnt < 0) {
return false;
}
}
}
return true;
}
}
WeChat:Saraad
2022-05-13