Short Elegant EasyUnderstanding Java Solution


  • 0
    H

    '''
    public class Solution {
    public boolean isOneEditDistance(String s, String t) {
    int s_len = s.length(), t_len = t.length(), i = 0, j = 0;
    boolean edited = false;
    int op = s_len - t_len;
    if (Math.abs(op) > 1) return false;

        while (i < s_len || j < t_len) {
            if (i < s_len && j < t_len && s.charAt(i) == t.charAt(j)) {
                i ++;
                j ++;
            } else {
                if (edited) return false;
                edited = true;
                if (op == 1) {i++;}
                else if (op == 0) {i++;j++;}
                else {j++;}
            }
        }
        return edited;
    }
    

    }
    '''


  • 0
    H

    Can anyone tell me how to use ''' to show the code elegantly? Tried many times, never succeed..


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.