From 7829298ceead045d5104ecf57ce34957fff73e0c Mon Sep 17 00:00:00 2001 From: suhwan2004 Date: Sat, 4 Jan 2025 00:17:58 +0900 Subject: [PATCH] commit --- ...umber of Different Integers in a String.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 suhwan2004/Number of Different Integers in a String.js diff --git a/suhwan2004/Number of Different Integers in a String.js b/suhwan2004/Number of Different Integers in a String.js new file mode 100644 index 0000000..3a1c206 --- /dev/null +++ b/suhwan2004/Number of Different Integers in a String.js @@ -0,0 +1,39 @@ +/* +22:39 ~ 22:47 + +Time : O(N) +Space : O(N) +ALGO : for +DS : hash Set, String +Constraints +- 1 <= word.length <= 1000 +- 주어지는 word는 숫자와 영소문자로 구성된다 +Edge Case : X +*/ +var numDifferentIntegers = function(word) { + let set = new Set() + let curDigit = '' + + for(let i = 0; i < word.length; i++){ + const curC = word[i] + const nextC = word[i+1] + if(curC >= 'a' && curC <= 'z'){ + if(curDigit){ + set.add(curDigit) + curDigit = '' + } + }else if(curDigit === '' && curC === '0') { + if(i === word.length-1 || (nextC >= 'a' && nextC <= 'z')) curDigit += curC + else continue; + }else { + curDigit += curC + } + } + + if(curDigit){ + set.add(curDigit) + curDigit = '' + } + + return set.size +}; \ No newline at end of file