how to tell if certain animation is playing unity code example

Example 1: how to know if the animator playing animation unity

bool AnimatorIsPlaying(){     return animator.GetCurrentAnimatorStateInfo(0).length >            animator.GetCurrentAnimatorStateInfo(0).normalizedTime;  }

Example 2: condition when a animation finishes in unity

if(anim.GetCurrentAnimatorStateInfo(0).normalizedTime > 1){  //If normalizedTime is 0 to 1 means animation is playing, if greater than 1 means finished
   Debug.Log("not playing"); 
 }
 else{  
      Debug.Log("playing");
 }