diff --git a/clojure/709.clj b/clojure/709.clj deleted file mode 100644 index ee38733..0000000 --- a/clojure/709.clj +++ /dev/null @@ -1,19 +0,0 @@ -(ns clojure.709 - (:require [clojure.string :as str] - [clojure.test :refer [deftest is run-tests]])) - -(defn to-lower-case [s] - (str/lower-case s)) - -(def resultado (to-lower-case "HELLO")) - -(println resultado) - -(deftest test-to-lower-case - (is (= "hello" (to-lower-case "HELLO"))) - (is (= "world" (to-lower-case "world"))) - (is (= "clojure" (to-lower-case "CloJure"))) - (is (= "" (to-lower-case ""))) - (is (= "123!@#" (to-lower-case "123!@#")))) - -(run-tests) diff --git a/solutions/0701-0800/0709-to-lower-case/README.md b/solutions/0701-0800/0709-to-lower-case/README.md new file mode 100644 index 0000000..49ac8d5 --- /dev/null +++ b/solutions/0701-0800/0709-to-lower-case/README.md @@ -0,0 +1,11 @@ +# 709. To Lower Case + +[LeetCode problem 709](https://leetcode.com/problems/to-lower-case/) + +- **Difficulty**: Easy +- **Tags**: string + +## Description + +Given a string `s`, return the string after converting every uppercase +letter to lowercase. diff --git a/solutions/0701-0800/0709-to-lower-case/solution.cpp b/solutions/0701-0800/0709-to-lower-case/solution.cpp new file mode 100644 index 0000000..f14275f --- /dev/null +++ b/solutions/0701-0800/0709-to-lower-case/solution.cpp @@ -0,0 +1,14 @@ +#include "solution.hpp" + +#include +#include + +namespace leetcode::p0709 { + +std::string solve(std::string s) { + std::ranges::transform( + s, s.begin(), [](unsigned char c) { return static_cast(std::tolower(c)); }); + return s; +} + +} // namespace leetcode::p0709 diff --git a/solutions/0701-0800/0709-to-lower-case/solution.hpp b/solutions/0701-0800/0709-to-lower-case/solution.hpp new file mode 100644 index 0000000..e30b0fd --- /dev/null +++ b/solutions/0701-0800/0709-to-lower-case/solution.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include + +namespace leetcode::p0709 { + +// optimized: O(n) time, O(n) space — map each character through +// std::tolower. +std::string solve(std::string s); + +} // namespace leetcode::p0709 diff --git a/solutions/0701-0800/0709-to-lower-case/test.cpp b/solutions/0701-0800/0709-to-lower-case/test.cpp new file mode 100644 index 0000000..4c2eec9 --- /dev/null +++ b/solutions/0701-0800/0709-to-lower-case/test.cpp @@ -0,0 +1,11 @@ +#include + +#include "solution.hpp" + +TEST_CASE("Problem 709", "[p0709]") { + CHECK(leetcode::p0709::solve("HELLO") == "hello"); + CHECK(leetcode::p0709::solve("world") == "world"); + CHECK(leetcode::p0709::solve("CloJure") == "clojure"); + CHECK(leetcode::p0709::solve("") == ""); + CHECK(leetcode::p0709::solve("123!@#") == "123!@#"); +}