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

Debug Spark 3.0 Kubernetes Runtime — Executor Pods restarts continuously

High Availability on Linux: The service IP address, part 2

Lets Get Started With Docker & Docker-Compose

What can we learn from Automation Testing failures?

GetX Flutter Firebase Auth Example

How to extend dotnet-dump (1/2) — What are the new commands?

Big Data vs. S3

Routing Tables

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

Error Handling with RxSwift

RxJava Completable equivalents in Apple’s Combine framework

REST Vs. WebSocket — Learn The Difference

Khipu: Rapid and Sustainable Software Creation in Swift using Engineering and Science Principles