11// debugger
2- import { format } from 'node:path' ;
32import { ExecutionTimer } from './time.js' ;
43import assert from 'node:assert/strict' ;
54import { count } from 'node:console' ;
6- import { lchown } from 'node:fs' ;
75
86/*
9722. Generate Parentheses
@@ -108,7 +106,7 @@ var findLongestWord = function (s, dictionary) {
108106 * Given two non-negative integers num1 and num2 represented as strings, return the product of num1 and num2, also represented as a string.
109107 * Note: You must not use any built-in BigInteger library or convert the inputs to integer directly.
110108 *
111- * Input num1 and num2 are 非負數以字串方式呈現
109+ * Input num1 and num2 非負數以字串方式呈現
112110 * Output num1 * num2(以字串方式呈現)
113111 * 不能使用內建含式或直接把Input轉成數字
114112 * -------------------------------------------
@@ -131,21 +129,23 @@ var findLongestWord = function (s, dictionary) {
131129 * @return {string }
132130 */
133131var multiply = function ( num1 , num2 ) {
132+ /**
133+ * 不能使用內建涵式或轉換型態
134+ */
134135
135- let pattern = / ^ [ 0 - 9 ] + $ / ;
136-
137- if ( ! num1 . match ( pattern ) || ! num2 . match ( pattern ) || Number ( num1 ) === 0 || Number ( num2 ) === 0 ) {
138- return ;
136+ let answer = Array ( num1 . length + num2 . length ) . fill ( 0 ) ;
137+ console . log ( answer )
138+ for ( let i = num1 . length - 1 ; i >= 0 ; i -- ) {
139+
139140 }
140-
141-
142-
143141} ;
144142// const num1 = "2", num2 = "3";
145143// "6"
146144// const num1 = "123", num2 = "456";
147145// "56088"
148- // console.log(multiply(num1, num2));
146+ const num1 = "123456789" , num2 = "987654321" ;
147+ // "121932631112635269"
148+ // console.log(multiply(num1, num2));ㄋㄋ
149149
150150
151151
@@ -1258,24 +1258,61 @@ var minRemoval = function(nums, k) {
12581258// console.log(minRemoval(nums,k));
12591259
12601260
1261- /**
1262- * 1653. Minimum Deletions to Make String Balanced
1261+ /***
1262+ * 890. Find and Replace Pattern
12631263 *
1264- * 參數s中只有'a' & 'b'這兩個字母。
1265- * 刪除任一字母使s balanced,若不存在一對index (i,j) 使得 i < j 且 s[i] = 'b' 且 s[j] = 'a',則s 是balanced。
1266- * 回傳最小須刪除幾次才能使s balanced
1267- *
1268- * @param {string } s
1269- * @return {number }
1264+ * @param {string[] } words
1265+ * @param {string } pattern
1266+ * @return {string[] }
12701267 */
1271- var minimumDeletions = function ( s ) {
1272-
1273- } ;
1274- // let s = "aababbab";
1275- /*Output: 2
1276- Explanation: You can either:
1277- Delete the characters at 0-indexed positions 2 and 6 ("aababbab" -> "aaabbb"), or
1278- Delete the characters at 0-indexed positions 3 and 6 ("aababbab" -> "aabbbb").
1279- */
1280- // console.log(minimumDeletions(s));
1268+ var findAndReplacePattern = function ( words , pattern ) {
1269+ // solution 1.
1270+ // TC: O(n * m)
1271+ // let result = [];
1272+ // for(let i = 0;i < words.length;i++) {
1273+ // if(checkEqual(words[i],pattern)){
1274+ // result.push(words[i]);
1275+ // }
1276+ // }
1277+ // return result;
1278+
1279+ // /**
1280+ // * @param {string } a
1281+ // * @param {string } b
1282+ // * @return {boolean }
1283+ // */
1284+ // function checkEqual(a,b) {
1285+ // for(let i = 0;i < a.length;i++) {
1286+ // if(a.indexOf(a[i]) !== b.indexOf(b[i])){
1287+ // return false;
1288+ // }
1289+ // }
1290+ // return true;
1291+ // }
1292+
1293+ // solution 2.
1294+ // hash map
1295+ let result = [ ] ;
1296+ for ( const a of words ) {
1297+ if ( checkEqual ( a , pattern ) ) {
1298+ result . push ( a ) ;
1299+ }
1300+ // console.log(a)
1301+ }
1302+
1303+ function checkEqual ( a , b ) {
1304+ let map = new Map ( ) ;
1305+ for ( let i = 0 ; i < a . length ; ++ i ) {
1306+ if ( ! map . has ( a [ i ] ) ) {
1307+ map . set ( i , a [ i ] ) ;
1308+ }
1309+ if ( map . get ( a [ i ] ) ) {
1310+
1311+ }
1312+ }
12811313
1314+ }
1315+ } ;
1316+ let word = [ "abc" , "deq" , "mee" , "aqq" , "dkd" , "ccc" ] , pattern = "abb" ;
1317+ // ["mee","aqq"]
1318+ // console.log(findAndReplacePattern(word,pattern));
0 commit comments