Here are some takeaways about how to design the key for you.
- When the order of each element in the string/array doesn't matter, you can use the
sorted string/arrayas the key.
- If you only care about the offset of each value, usually the offset from the first value, you can use the
offsetas the key.
- In a tree, you might want to directly use the
TreeNodeas key sometimes. But in most cases, theserialization of the subtreemight be a better idea.
- In a matrix, you might want to use
the row indexorthe column indexas key. - In a Sudoku, you can combine the row index and the column index to identify which
blockthis element belongs to.
- Sometimes, in a matrix, you might want to aggregate the values in the same
diagonal line.
No comments:
Post a Comment