“Powtórz podany ciąg dokładnie N razy” Kod odpowiedzi

Powtórz podany ciąg dokładnie N razy

// Repeat the given string exactly n times
fn repeat_str(src: &str, count: usize) -> String {
  vec![src; count].join("")
}
Mackerel

Powtórz podany ciąg dokładnie N razy

# Repeat the given string exactly n times
def repeat_str (n, s)
  s*n
end
Mackerel

Powtórz podany ciąg dokładnie N razy

// Repeat the given string exactly n times
import java.util.Collections
object StringRepeat {
  def repeatStr(times: Int, str: String): String = {
    str * times
  }
}
Mackerel

Powtórz podany ciąg dokładnie N razy

// Repeat the given string exactly n times
public class Solution {
    public static String repeatStr(final int repeat, final String string) {
        String repeatedString = "";
        for (int i = 0; i < repeat; i++) {
          repeatedString += string;
        }
        return repeatedString;
    }
}
import java.util.Collections;
public class Solution {
    public static String repeatStr(final int repeat, final String string) {
        return repeat < 0 ? "" : String.join("", Collections.nCopies(repeat, string));
    }
}
Mackerel

Odpowiedzi podobne do “Powtórz podany ciąg dokładnie N razy”

Pytania podobne do “Powtórz podany ciąg dokładnie N razy”

Więcej pokrewnych odpowiedzi na “Powtórz podany ciąg dokładnie N razy” w Rust

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu