From ef0187064b7603a424fa45be99608ed4302bcc79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Borba?= Date: Sat, 19 Sep 2026 09:15:50 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9F=A2=20Port=20problem=20709=20(To=20Low?= =?UTF-8?q?er=20Case)=20from=20Clojure=20to=20C++23?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces clojure/709.clj with solutions/0701-0800/0709-to-lower-case/. --- clojure/709.clj | 19 ------------------- .../0701-0800/0709-to-lower-case/README.md | 11 +++++++++++ .../0701-0800/0709-to-lower-case/solution.cpp | 14 ++++++++++++++ .../0701-0800/0709-to-lower-case/solution.hpp | 11 +++++++++++ .../0701-0800/0709-to-lower-case/test.cpp | 11 +++++++++++ 5 files changed, 47 insertions(+), 19 deletions(-) delete mode 100644 clojure/709.clj create mode 100644 solutions/0701-0800/0709-to-lower-case/README.md create mode 100644 solutions/0701-0800/0709-to-lower-case/solution.cpp create mode 100644 solutions/0701-0800/0709-to-lower-case/solution.hpp create mode 100644 solutions/0701-0800/0709-to-lower-case/test.cpp 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!@#"); +}