-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
202 lines (178 loc) · 7.61 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<script src="https://telegram.org/js/telegram-web-app.js"></script>
<title>Leetcode tasks</title>
</head>
<body>
<div class="container">
<section class="section two-sum">
<h2>1. Two sum</h2>
<p class="section__description">Дан список из целых чисел (массив) и число-цель. Найти в списке два числа, сумма которых равна цели, и вывести их порядковые номера (индексы) из первоначального списка (начинается с нуля).</p>
<input type="text" data-sum-array="">
<input type="text" data-sum-target="">
<button data-sum-btn="">Найти</button>
<div class="result" data-sum-result=""></div>
<div class="spoiler">
<div class="spoiler__button">Посмотреть код</div>
<div class="spoiler__drop">
<code>
var twoSum = function(nums, target) {<br>
<br>
const numsClone = [];<br>
<br>
for (let item in nums) {<br>
numsClone[item] = nums[item]<br>
}<br>
<br>
let currNums;<br>
<br>
outer: for (let i=0; i < numsClone.length; i++) {<br>
<br>
for (let x=1; x < numsClone.length; x++) {<br>
<br>
let sum = numsClone[0] + numsClone[x];<br>
<br>
if (sum === target) {<br>
currNums = [numsClone[0], numsClone[x]];<br>
break outer;<br>
}<br>
};<br>
<br>
numsClone.push(numsClone[0]);<br>
numsClone.splice(0, 1);<br>
};<br>
<br>
let indexNums = [nums.indexOf(currNums[0]), nums.lastIndexOf(currNums[1])];<br>
<br>
return indexNums;<br>
}
</code>
</div>
</div>
</section>
<section class="section palindrome">
<h2>9. Palindrome Number</h2>
<p class="section__description">Дано число. Нужно проверить, является ли оно палиндромом.</p>
<p>Палиндром — число, которое читается одинаково в любом направлении.</p>
<input type="text" data-palindrome-input="">
<button data-palindrome-btn="">Проверить</button>
<div class="result" data-palindrome-result=""></div>
<div class="spoiler">
<div class="spoiler__button">Посмотреть код</div>
<div class="spoiler__drop">
<code>
var isPalindrome = function(x) {<br>
<br>
let mass = String(x).split('');<br>
let massReverse = mass.reverse();<br>
let xReverse = massReverse.join('');<br>
<br>
return x === Number(xReverse);<br>
<br>
};
</code>
</div>
</div>
</section>
<section class="section integer-romans">
<h2>12. Integer to Roman</h2>
<p class="section__description">Конвертировать арабские числа в римские.</p>
<input type="text" data-integer-input="">
<button data-integer-btn="">Гоу</button>
<div class="result" data-integer-result=""></div>
<div class="spoiler">
<div class="spoiler__button">Посмотреть код</div>
<div class="spoiler__drop">
<code>
var intToRoman = function(num) {<br>
<br>
let inpMass = String(num).split("");<br>
<br>
switch (inpMass.length) {<br>
case 1:<br>
return convert("I", "V", "X", 0);<br>
<br>
case 2:<br>
return convert("X", "L", "C", 0) + convert("I", "V", "X", 1);<br>
<br>
case 3:<br>
return (<br>
convert("C", "D", "M", 0) +<br>
convert("X", "L", "C", 1) +<br>
convert("I", "V", "X", 2)<br>
);<br>
<br>
case 4:<br>
let number = [];<br>
for (let x = 0; x < Number(inpMass[0]); x++) {<br>
number.push("M");<br>
}<br>
return (<br>
number.join("") +<br>
convert("C", "D", "M", 1) +<br>
convert("X", "L", "C", 2) +<br>
convert("I", "V", "X", 3)<br>
);<br>
}<br>
<br>
function convert(firstNum, middleNum, lastNum, indx) {<br>
if (inpMass[indx] - 5 === 0) {<br>
return middleNum;<br>
} else if (inpMass[indx] - 5 > 0) {<br>
if (inpMass[indx] - 5 === 4) return firstNum + lastNum;<br>
<br>
let result = [middleNum];<br>
<br>
for (let i = 0; i < inpMass[indx] - 5; i++) {<br>
result.push(firstNum);<br>
}<br>
<br>
return result.join("");<br>
} else if (inpMass[indx] - 5 < 0) {<br>
if ((inpMass[indx] - 5) * -1 === 1) return firstNum + middleNum;<br>
<br>
let result = [];<br>
<br>
for (let i = 0; i < Number(inpMass[indx]); i++) {<br>
result.push(firstNum);<br>
}<br>
return result.join("");<br>
}<br>
}<br>
}
</code>
</div>
</div>
</section>
<section class="section romans">
<h2>13. Roman to Integer</h2>
<p class="section__description">Конвертировать римские числа в арабские.</p>
<input type="text" data-romans-input="">
<button data-romans-btn="">Гоу</button>
<div class="result" data-romans-result=""></div>
<div class="spoiler">
<div class="spoiler__button">Посмотреть код</div>
<div class="spoiler__drop">
<code>
var isPalindrome = function(x) {<br>
<br>
let mass = String(x).split('');<br>
let massReverse = mass.reverse();<br>
let xReverse = massReverse.join('');<br>
<br>
return x === Number(xReverse);<br>
<br>
};
</code>
</div>
</div>
</section>
</div>
<script type="module" src="app.js"></script>
</body>
</html>