521. Longest Uncommon Subsequence I

LeetCode easy original: C# #csharp #easy #leetcode #math #search #string
Il testo del problema è tradotto dal russo per la lingua selezionata. Il codice resta invariato.

given две строки a и b. return длину самой длинной несообщей подпоследовательности между a и b. Если такой несообщей подпоследовательности не существует, return -1.

Несообщая subsequence между двумя stringaми — это stringa, которая является subsequenceю только одной из них.

Esempio:

Input: a = "aba", b = "cdc"

Output: 3

Explanation: One longest uncommon subsequence is "aba" because "aba" is a subsequence of "aba" but not "cdc".

Note that "cdc" is also a longest uncommon subsequence.

C# soluzione

abbinato/originale
public class Solution {
    public int FindLUSlength(string a, string b) {
        if (a == b) {
            return -1;
        } else {
            return Math.Max(a.Length, b.Length);
        }
    }
}

C++ soluzione

bozza automatica, rivedere prima dell'invio
#include <bits/stdc++.h>
using namespace std;

// Auto-generated C++ draft from the C# solution. Review containers, LINQ and helper types before submit.
class Solution {
public:
    public int FindLUSlength(string a, string b) {
        if (a == b) {
            return -1;
        } else {
            return max(a.size(), b.size());
        }
    }
}

Java soluzione

abbinato/originale
class Solution {
    public int findLUSlength(String a, String b) {
        if (a.equals(b)) {
            return -1;
        } else {
            return Math.max(a.length(), b.length());
        }
    }
}

JavaScript soluzione

abbinato/originale
var findLUSlength = function(a, b) {
    if (a === b) {
        return -1;
    } else {
        return Math.max(a.length, b.length);
    }
};

Python soluzione

abbinato/originale
class Solution:
    def findLUSlength(self, a: str, b: str) -> int:
        if a == b:
            return -1
        else:
            return max(len(a), len(b))

Go soluzione

abbinato/originale
func findLUSlength(a string, b string) int {
    if a == b {
        return -1
    } else {
        if len(a) > len(b) {
            return len(a)
        } else {
            return len(b)
        }
    }
}

Algorithm

Если stringa a равна строке b, return -1, так как не существует несообщей подпоследовательности.

В противном случае: Вычислите длины строк a и b. return длину более длинной строки.

😎

Vacancies for this task

offerte attive with overlapping task tags are mostrati.

Tutte le offerte
Non ci sono ancora offerte attive.