How to display sticky or latest published post on the current category page it belongs to?

This code is certainly not perfect but it actually does the job :

<?php
// Store the current category ID :
$current_object = get_queried_object_id();

// Get sticky post :
$args = array(
  'posts_per_page'      => 1,
  'post__in'            => get_option( 'sticky_posts' ),
  'cat'                 => $current_object,
  'ignore_sticky_posts' => true,
);
$sticky_query = new WP_query( $args );

// Get latest post :
$args = array(
  'posts_per_page'      => 1,
  'cat'                 => $current_object,
  'ignore_sticky_posts' => true,
);
$latest_query = new WP_query( $args );

// If there is a sticky post in the current category :
if ( $sticky_query->have_posts() ) : ?>

  <div class="sticky-post">

    <?php
    while ( $sticky_query->have_posts() ) :
      $sticky_query->the_post();

      the_title();

    endwhile;
    wp_reset_postdata();
    ?>

  </div>

<?php
// If there is no sticky post, display the latest published post :
elseif ( $latest_query->have_posts() ) : ?>

  <div class="latest-post">

    <?php
    while ( $latest_query->have_posts() ) :
      $latest_query->the_post();
      
      the_title();

    endwhile;
    wp_reset_postdata();
    ?>

  </div>

<?php endif; ?>

There is two queries here. The first one to get and display the sticky post that belongs to the current category, the second one to get and display the latest post in the same category (if there is no sticky post to display).