Skip to content

Commit a46aeb7

Browse files
committed
練習js 解題,oop練習寫繼承
1 parent e406357 commit a46aeb7

8 files changed

Lines changed: 42 additions & 3 deletions

File tree

javascript/LeetCode/math/3602.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* 3602. Hexadecimal and Hexatrigesimal Conversion
3+
*
4+
* hexadecimal = base 16,使用數字0 - 9和大寫A - F代表0 - 15
5+
* hexatrigesimal = base 16,使用數字0 - 9和大寫A - Z代表0 - 35
6+
* 取得hexadecimal的n的二次方(n * 2)和hexatrigesimal的n的三次方(n * 3)串連
7+
* @param {number} n
8+
* @return {string}
9+
*/
10+
var concatHex36 = function(n) {
11+
return ((n ** 2).toString(16) + (n ** 3).toString(36)).toUpperCase();
12+
};
13+
let n = 36
14+
/**
15+
* Output: "5101000"
16+
n2 = 36 * 36 = 1296. In hexadecimal, it converts to (5 * 162) + (1 * 16) + 0 = 1296, which corresponds to "510".
17+
n3 = 36 * 36 * 36 = 46656. In hexatrigesimal, it converts to (1 * 363) + (0 * 362) + (0 * 36) + 0 = 46656, which corresponds to "1000".
18+
Concatenating both results gives "510" + "1000" = "5101000".
19+
*
20+
*/
21+
console.log(concatHex36(n));

javascript/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// debugger
2+
import { format } from 'node:path';
23
import {ExecutionTimer} from './time.js';
34
import assert from 'node:assert/strict';
45

@@ -1028,9 +1029,6 @@ var closetPair = function(arr1,arr2,x) {
10281029
// [1,30];
10291030
// console.log(closetPair(arr1,arr2,x));
10301031

1031-
1032-
1033-
10341032
/**
10351033
* 166. Fraction to Recurring Decimal
10361034
*

python/index.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
greek.environment()
3232
greek.attack()
3333
greek.affend()
34+
print(greek.specice)
3435

3536
# lion = Lion("獅子","未知","肉食")
3637
# lion.eat()

python/oop/Testudo_graeca.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# 歐洲陸龜
2+
from oop.Tortoise import Tortoise
3+
4+
# 繼承自父類別(Tortoise),可以把該類別想成是孫子(Multilevel Inheritance),它的上一輩是Single Inheritance
5+
class Testudo_graeca(Tortoise):
6+
def __init__(self, name, age, food, speciceType):
7+
super().__init__(name, age, food, speciceType)

python/oop/Tortoise.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
# 陸龜
12
from oop.Animal import Animal
23

34
class Tortoise(Animal):
5+
6+
# class variable
7+
# a property of the class itself.
8+
specice = "Spurred tortoise"
49

510
def __init__(self, name, age, food,speciceType:str):
11+
# instance variable.Unique to each instance
612
super().__init__(name, age, food)
713
self.speciceType = speciceType
814

python/oop/Turtle.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# 澤龜
2+
from oop.Animal import Animal
3+
4+
class Turtle(Animal):
5+
def __init__(self, name, age, food):
6+
super().__init__(name, age, food)
-1 Bytes
Binary file not shown.
36 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)