Преглед на файлове

Adding Solution for 3637

Vinicius Teshima преди 1 седмица
родител
ревизия
f9607ecaf8
променени са 3 файла, в които са добавени 57 реда и са изтрити 2 реда
  1. 51 0
      TypeScript/3637.ts
  2. 6 0
      TypeScript/build.sh
  3. 0 2
      build.sh

+ 51 - 0
TypeScript/3637.ts

@@ -0,0 +1,51 @@
+// 3637. Trionic Array I
+
+
+function isTrionic(nums: number[]): boolean {
+    if ( nums.length < 4 ) { return false }
+
+    function isIncreasing(ns: number[]): boolean {
+        let len: number = ns.length
+        if ( len == 1 ) { return false }
+        len--
+        let i: number = 0
+        while ( i < len ) { if ( ns[i] >= ns[i+1] ) { return false } i++ }
+        return true
+    }
+
+    function isDecreasing(ns: number[]): boolean {
+        let len: number = ns.length
+        if ( len == 1 ) { return false }
+        len--
+        let i: number = 0
+        while ( i < len ) { if ( ns[i] <= ns[i+1] ) { return false } i++ }
+        return true
+    }
+
+    let p: number = 1
+    let q: number = 2
+    let nlen: number = nums.length - 1
+
+    while ( true ) {
+        if ( isIncreasing(nums.slice(0, p+1))
+             && isDecreasing(nums.slice(p, q+1))
+             && isIncreasing(nums.slice(q)) ) { return true }
+        q++
+        if ( q >= nlen ) {
+            p++
+            q = p+1
+            if ( q >= nlen ) { return false }
+        }
+    }
+
+    return false
+};
+
+function main() {
+    function r(n: number[]) { console.log(`[${n}] = ${isTrionic(n)}`) }
+    r([1,3,5,4,2,6])
+    r([2,1,3])
+    r([1,2,1,2])
+}
+
+main()

+ 6 - 0
TypeScript/build.sh

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

+ 0 - 2
build.sh

@@ -1,12 +1,10 @@
 #!/bin/sh
 
-
 newest_dir="$(find ./ -type f -printf "%T@ %p\n" \
                 | sort -n \
                 | cut -d' ' -f 2- \
                 | tail -n 1 \
                 | xargs dirname)"
 
-
 sh $newest_dir/build.sh