Swift LeetCode #9

Input: x = 121
Output: true
Input: x = -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
Input: x = 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
Input: x = -101
Output: false
func isPalindrome(_ x: Int) -> Bool { if x < 0 { return false } var origin = x var reverse : Int = 0 while origin != 0 {  reverse = reverse*10 + origin%10  origin /= 10  } return x == reverse}

--

--

--

Major in physical education. Football referee. And high interest in looking the world through the numbers.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

A S.I.M.P.L.E Tool to Analyze Value

Smooth out jerky movement in Unity

Eel: The Frontend Like GUI For Python (HTML &CSS)

KeplerSwap, The Next Celestial Body In The Defi Solar System

Selenium — Learn How To Scrape Website with Python

Who the f**k is a Perfect Developer!

Sets (in Ruby)

Hadoop MapReduce Articles Summary

Easily Understand MapReduce Technology. Do you know What is Hadoop MapReduce Technology? Demystifying MapReduce Technology.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Mario tsai

Mario tsai

Major in physical education. Football referee. And high interest in looking the world through the numbers.

More from Medium

[LeetCode] 1913. Maximum Product Difference Between Two Pairs (Swift)

Observation are glorified GO-TO statements

Left Rotation HackerRank Swift Solution

1- What Widgets cannot do ?