The main difference between one-hot-encoding and integer-encoding is based on the ordinal relationship between the classes. It means when you apply one-hot-encoding on classes, the distance between class 4 and 5 is equal to the distance of class 4 and 10.
So, both of your approach is totally correct and making the decision of which approach should be taken, is with the nature of your data, but you should note that for classification purpose between multi classes, in many cases, one-hot-encoding can give you the better result(because many ML algorithms are better to work with that such as SVM)
Why use one hot encoding instead of integer encoding? - Part 1 (2019) - fast.ai Course Forums
python - Difference between one-hot-encoded and integer output in Sklearn - Stack Overflow
comment:re sklearn -- integer encoding vs 1-hot (py)
Reasons not to one-hot-encode categorical features - Cross Validated
A note on terminology: As far as I am aware (unfortunately, there are a lot of blogs written by people who overlook the subtle differences and thus mis-information spreads):
One hot encoding is exactly what you described, generating a map from each unique value in a string column to an integer
Dummying is making K new columns (in which K is the number of unique values), of which exactly one column per row must be one.
In the "dog, cat, horse" example, when using a decision tree, consider the following example. Perhaps your target variable is "has it ever meowed?". Clearly what you want your decision tree to do is be able to ask the question "is it a cat? (yes/no)".
If you one-hot encode, such that dog -> 0, cat-> 1, horse->2, the tree can't isolate all of the cats using one question, because decision trees always split using "is feature x greater than or less than X?"
If you're using logistic regression, it also can't assign higher probabilities of meowing to cats.
If you dummy, the tree can explicitly ask the question "the column which signifies cat greater than 0.5?", thus splitting your data into cats and not cats.
If you use logistic regression, your optimiser can learn that the coefficient related to this column should be positive.
Thus in my opinion, whenever you have categorical data which has no implicit ordinality, always dummy, never one-hot encode.
In the case where your data has high cardinality, this could cause problems, especially if the number of examples of each type is tiny, but this is a problem you can't really solve, you simply have too detailed information for the size of your training data and using it would lead to over-fitting.
Nonetheless, one way to mitigate this, is to do some manual clustering (or actual clustering), in which you make a synthetic column, which can take fewer values, and many of the unique values of the original column map to the same value in the new column (e.g. dog, cat, horse-> mammal, pigeon, parrot , chicken -> bird). This makes it easier for the algorithm to learn, and if there's enough data, it can split further within each cluster.
I have never been happy with one hot encoding.
See: https://roamanalytics.com/2016/10/28/are-categorical-variables-getting-lost-in-your-random-forests/
Recently, I have tried CatBoost (http://CatBoost.ai), Open Source from Yandex.
CatBoost uses Categorical variables directly. (XGBoost uses one-hot-encoding under the covers.)
It seems to score better and faster than H2O's XGBoost, but training seems to take longer.
You might want to give it a try.