From c7a6dad60a96ddfe72b2cb956d528d754de6b91a Mon Sep 17 00:00:00 2001 From: agusmakmun <summon.agus@gmail.com> Date: Sun, 22 May 2016 04:13:27 +0700 Subject: [PATCH] added post: notPaired [CF] --- _posts/2016-05-21-notpaired-cf.md | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 _posts/2016-05-21-notpaired-cf.md diff --git a/_posts/2016-05-21-notpaired-cf.md b/_posts/2016-05-21-notpaired-cf.md new file mode 100644 index 0000000..8f370b2 --- /dev/null +++ b/_posts/2016-05-21-notpaired-cf.md @@ -0,0 +1,38 @@ +--- +layout: post +title: "notPaired [CF]" +date: 2016-05-22 04:10:03 +0700 +categories: [python, codefights] +--- + +Author Question: **Lepluto** + +In Numberland, every integer living there has a soulmate which is the exact same number. To prevent family disasters, the Numberland mayor made sure that there is no more than two of a certain number. However, he clearly forgot to create a pair for one of the numbers, making it very sad and lonely. Given the array representing Numberland's citizens, your task is to find which number you need to add to the array so that everyone has a pair. + +**Example:** + +* `notPaired([1, 2, 1]) = 2` + 2 is the only number in the sequence that appears once. + +* `notPaired([1, 3, 5, 7, 9, 7, 5, 3, 1]) = 9` + 9 is the only number in the sequence that appears once. + +**Input/Output** + +* **[input] array.integer numberland** + 1 ≤ numberland.length ≤ 100 + +* **[output] integer** + The final soulmate you need to add to Numberland in order to make everyone happy. + +**Solution:** + +```python +def notPaired(numberland): + for x in numberland: + if numberland.count(x) == 1: return x + +>>> notPaired([1, 3, 5, 7, 9, 7, 5, 3, 1]) +9 +>>> +``` \ No newline at end of file -- GitLab