Deﬁne $f(x)$ to be the distance from x to the nearest integer. What are the critical points of f? From how I understood the question and judging from solutions I've been provided with (see graph below),

$f(x)$ starts from an x-position, which should be an integer, and assuming this goes on for all integers until infinity.  
I also assume the graph follows the function $f(x)=x$, whereby  $0\le  y  \le 0.5$ to make sure the function returns to the nearest integer.  
If not, can $f(x)$ be equal to any function as long as it occupies the distance from $x$ to the next integer? For example, $f(x)=2x$ whereby $0\le y \le 1$

And can we say the critical points are all integers? Or maybe I did not understand the question well.

Your first graph is the correct one for $f(x)$, and $f$ is well-defined by the definition in your title--although I might rather say "...to a nearest integer" since more than one could be "nearest."
You are correct that all integers are critical points of $f$. Those are the bottom corners in your graph. However, you missed some critical points, the ones halfway between two consecutive integers--i.e. the values $n+\frac 12$ where $n$ is an integer. Those are the top corners in your graph.
All other points have a derivative of $1$ or $-1$, so we have found all the critical points of $f$.
