1
0

3 Commity 710191e357 ... 40c28cf4ea

Autor SHA1 Správa Dátum
  Vinicius Teshima 40c28cf4ea Adding solution for 2108 10 mesiacov pred
  Vinicius Teshima 5d7d142ba7 Adding even faster solution for 2006 10 mesiacov pred
  Vinicius Teshima 732dcaccdd Adding solution for 2006 10 mesiacov pred
5 zmenil súbory, kde vykonal 100 pridanie a 0 odobranie
  1. 1 0
      .python-version
  2. 45 0
      C++/2108.cpp
  3. 7 0
      C++/build.sh
  4. 40 0
      Python/2006.py
  5. 7 0
      Python/build.sh

+ 1 - 0
.python-version

@@ -0,0 +1 @@
+3.13

+ 45 - 0
C++/2108.cpp

@@ -0,0 +1,45 @@
+#include <iostream>
+#include <cstdint>
+#include <vector>
+#include <string>
+
+using std::vector;
+using std::string;
+
+class Solution {
+public:
+    string firstPalindrome(vector<string>& words) {
+        auto isPalindrome = [](string s) {
+            unsigned int i = 0;
+            unsigned int j = s.size() - 1;
+            while ( j > i ) {
+                if ( s[i] != s[j] ) { return false; }
+                ++i; --j;
+            }
+            return true;
+        };
+        auto len = words.size();
+        auto i = len;
+        for ( i = 0; i < len; ++i ) {
+            if ( isPalindrome(words[i]) ) { return words[i]; }
+        }
+        return "";
+    }
+};
+
+void r(vector<string>& w) {
+    std::cout << "Solution().firstPalindrome([";
+    for ( uint64_t i = 0; i < w.size(); ++i ) {
+        if ( i == 0 ) { std::cout << "\"" << w[i] << "\""; continue; }
+        std::cout << ", \"" << w[i] << "\"";
+    }
+    std::cout << "]) = \"" << Solution().firstPalindrome(w) << "\"";
+};
+
+int main(void) {
+
+    vector<string> w1 = {"abc", "car", "ada", "racecar", "cool"};
+    r(w1);
+
+    return 0;
+}

+ 7 - 0
C++/build.sh

@@ -0,0 +1,7 @@
+#!/bin/sh
+
+newest_file="$(find ./ -type f -printf "%T@ %p\n" | sort -n | cut -d' ' -f 2- | tail -n 1)"
+
+set -x
+g++ -O0 -ggdb -Wall -Wextra -Werror $newest_file -o /tmp/out || exit 1
+/tmp/out

+ 40 - 0
Python/2006.py

@@ -0,0 +1,40 @@
+# 2006. Count Number of Pairs With Absolute Difference K
+
+import sys
+from typing import List
+
+
+class Solution:
+    def countKDifference(self, nums: List[int], k: int) -> int:
+        r: int = 0
+        i: int = 0
+        l: int = len(nums)
+        while i < l:
+            j: int = i
+            while j < l:
+                if abs(nums[i] - nums[j]) == k:
+                    r += 1
+                    pass
+                j += 1
+                pass
+            i += 1
+            pass
+        return r
+    pass
+
+
+def main() -> int:
+    def r(ns: List[int], k: int) -> None:
+        print(
+            f"Solution().countKDifference({ns}, {k}) = {Solution().countKDifference(ns, k)}"
+        )
+        pass
+
+    r([1, 2, 2, 1], 1)
+    r([1, 3], 3)
+    r([3, 2, 1, 5, 4], 2)
+    return 0
+
+
+if __name__ == "__main__":
+    sys.exit(main())

+ 7 - 0
Python/build.sh

@@ -0,0 +1,7 @@
+#!/bin/sh
+
+newest_file="$(find ./ -type f -printf "%T@ %p\n" | sort -n | cut -d' ' -f 2- | tail -n 1)"
+
+set -x
+python $newest_file
+