LeetCode Courses 3908. Valid Digit Number
LeetCode

3908. Valid Digit Number

We cast the number to a string to check for the digit while guarding against a leading match. The "cast-to-string for digit-level checks" trick is a Python staple worth pocketing.

1 chapter Beginner Written walk-through Updated 5 May 2026 Phil · @FirnoxGames
Free

Free for everyone. No account needed.

Start reading →

What you'll learn

1 3908. Valid Digit Number 📖 6 min read

We cast the number to a string to check for the digit while guarding against a leading match. The "cast-to-string for digit-level checks" trick is a Python staple worth pocketing.

In this chapter
  1. Problem
  2. String cast
  3. No string cast

Problem

You are given an integer n and a digit x.

A number is considered valid if:

  • It contains at least one occurrence of digit x, and
  • It does not start with digit x.

Return true if n is valid, otherwise return false.

Included with this course
📖Written version of every chapter