Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Bug Report for anagram-groups #3954

Closed
Closed
@Moritzz00

Description

@Moritzz00

Bug Report forhttps://neetcode.io/problems/anagram-groups

Please describe the bug below and include any steps to reproduce the bug or screenshots if possible.

I noticed that my solution didnt even get properly tested. I only got the error "Solution is not defined". I dont really know how I got the buf or how to reproduce it, but I can show the code that threw the error:

testing to just return the solution to one test case:
Image

error message:
Image

compelte code:
class result {
/**
*@param {string[]} strs
*@return {string[][]}
*
* idea: build a map for each string
* compare map for with map of each group
* if it is in group, add string to group
* else add a new group with the string to the result
*/
groupAnagrams(strs) {
let solution = [["x"]]
return solution
// O(m)
for (const string of strs) {
const currentMap = new Map()
// O(26)
for (const letter of alphabet) {
currentMap.set(letter, 0)
}
// O(n)
for (const letter of string) {
currentMap.set(letter, currentMap.get(letter) + 1)
}
let anagramFound = false
// O(1 + 2 + 3 + 4 + ... + m) = O(m)
for (const resultMap of result) {
// O(n)
if (this.compareMaps(currentMap, resultMap)) {
resultMap.set("result", resultMap.get("result").push(string))
anagramFound = true
}
}
if (!anagramFound) {
currentMap.set("result", string)
result.push(currentMap)
}
}
let finalResult = []
for (const resultMap of result) {
finalResult.push(resultMap.get("result"))
}

    return finalResult}/** * @param {Map(), Map()} map1, map2 * @return {bool} *  * assumes first map doesnt have a result entry*/compareMaps(map1, map2) {    for (key of map1.keys()) {        if (map1.get(key) !== map2.get(key)) {            return false        }    }    return true}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp