diff --git a/.github/workflows/npm-grunt.yml b/.github/workflows/npm-grunt.yml new file mode 100644 index 0000000..1f2d88e --- /dev/null +++ b/.github/workflows/npm-grunt.yml @@ -0,0 +1,28 @@ +name: NodeJS with Grunt + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [14.x, 16.x, 18.x] + + steps: + - uses: actions/checkout@v4 + + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + + - name: Build + run: | + npm install + grunt diff --git a/.github/workflows/npm-publish-github-packages.yml b/.github/workflows/npm-publish-github-packages.yml new file mode 100644 index 0000000..0f838d5 --- /dev/null +++ b/.github/workflows/npm-publish-github-packages.yml @@ -0,0 +1,36 @@ +# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created +# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages + +name: Node.js Package + +on: + release: + types: [created] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v3 + with: + node-version: 16 + - run: npm ci + - run: npm test + + publish-gpr: + needs: build + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v3 + with: + node-version: 16 + registry-url: https://npm.pkg.github.com/ + - run: npm ci + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/findWords.js b/findWords.js new file mode 100644 index 0000000..63c270f --- /dev/null +++ b/findWords.js @@ -0,0 +1,50 @@ +/** + * @param {character[][]} board + * @param {string[]} words + * @return {string[]} + */ +var findWords = function(board, words) { + let result = [] + let root = buildTrie(words) + + for(let i = 0; i< board.length ;i++){ + for(let j=0;j board.length -1 || j > board[0].length-1) return + if(!node[board[i][j]]) return + + let c = board[i][j] + board[i][j] = '#' + + dfs(node[c],i+1,j,result,board) + dfs(node[c],i-1,j,result,board) + dfs(node[c],i,j+1,result,board) + dfs(node[c],i,j-1,result,board) + board[i][j] = c + +} + +function buildTrie(words){ + let root = {} + + for(let word of words){ + let currNode = root + + for(let char of word){ + if(!currNode[char]) currNode[char] = {} + currNode = currNode[char] + } + currNode.word = word + } + return root +} \ No newline at end of file