one hot encoding target variable in tree and non tree (knn) methods
The answer depends on the library you are using. If you are using scikit - you wouldn't need to one hot encode the targets. Scikit handles it automatically.
If you were using keras to build a neural network, you might want to use one hot encoded labels because the built in loss function in keras (e.g categorical crossentropy) expects labels to be one hot encoded.
So both approaches work and ate a function of the library or tools you use.