Skip to content

Commit 6be1a7a

Browse files
committed
maths
1 parent 672904a commit 6be1a7a

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"cells": [],
3+
"metadata": {},
4+
"nbformat": 4,
5+
"nbformat_minor": 2
6+
}

Mathematical .ipynb

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,46 @@
587587
"print(LargestPrimeFactor(15))"
588588
]
589589
},
590+
{
591+
"cell_type": "code",
592+
"execution_count": 1,
593+
"metadata": {},
594+
"outputs": [
595+
{
596+
"name": "stdout",
597+
"output_type": "stream",
598+
"text": [
599+
"15\n"
600+
]
601+
}
602+
],
603+
"source": [
604+
"\"\"\"\n",
605+
"1281. Subtract the Product and Sum of Digits of an Integer\n",
606+
"Given an integer number n, return the difference between the product of its digits and the sum of its digits.\n",
607+
" \n",
608+
"Input: n = 234\n",
609+
"Output: 15 \n",
610+
"Explanation: \n",
611+
"Product of digits = 2 * 3 * 4 = 24 \n",
612+
"Sum of digits = 2 + 3 + 4 = 9 \n",
613+
"Result = 24 - 9 = 15\n",
614+
"\"\"\"\n",
615+
"from typing import List\n",
616+
"def subtractProductAndSum(n: int) -> int:\n",
617+
" prod = 1;\n",
618+
" sumation = 0\n",
619+
" temp = n;\n",
620+
" while temp > 0:\n",
621+
" rem = temp%10\n",
622+
" prod *= rem\n",
623+
" sumation += rem\n",
624+
" temp = temp // 10;\n",
625+
" return prod - sumation\n",
626+
"\n",
627+
"print(subtractProductAndSum(234))"
628+
]
629+
},
590630
{
591631
"cell_type": "code",
592632
"execution_count": null,
@@ -611,7 +651,7 @@
611651
"name": "python",
612652
"nbconvert_exporter": "python",
613653
"pygments_lexer": "ipython3",
614-
"version": "3.6.5"
654+
"version": "3.7.4"
615655
}
616656
},
617657
"nbformat": 4,

0 commit comments

Comments
 (0)