@@ -50,13 +50,52 @@ This is the highest among any shorthand color.
50
50
### ** Python3**
51
51
52
52
``` python
53
-
53
+ class Solution :
54
+ def similarRGB (self , color : str ) -> str :
55
+ def f (x ):
56
+ y, z = divmod (int (x, 16 ), 17 )
57
+ if z > 8 :
58
+ y += 1
59
+ return ' {:02x } ' .format(17 * y)
60
+
61
+ a, b, c = color[1 :3 ], color[3 :5 ], color[5 :7 ]
62
+ return f ' # { f(a)}{ f(b)}{ f(c)} '
54
63
```
55
64
56
65
### ** Java**
57
66
58
67
``` java
68
+ class Solution {
69
+ public String similarRGB (String color ) {
70
+ String a = color. substring(1 , 3 ), b = color. substring(3 , 5 ), c = color. substring(5 , 7 );
71
+ return " #" + f(a) + f(b) + f(c);
72
+ }
73
+
74
+ private String f (String x ) {
75
+ int q = Integer . parseInt(x, 16 );
76
+ q = q / 17 + (q % 17 > 8 ? 1 : 0 );
77
+ return String . format(" %02x" , 17 * q);
78
+ }
79
+ }
80
+ ```
59
81
82
+ ### ** Go**
83
+
84
+ ``` go
85
+ func similarRGB (color string ) string {
86
+ f := func (x string ) string {
87
+ q , _ := strconv.ParseInt (x, 16 , 64 )
88
+ if q%17 > 8 {
89
+ q = q/17 + 1
90
+ } else {
91
+ q = q / 17
92
+ }
93
+ return fmt.Sprintf (" %02x " , 17 *q)
94
+
95
+ }
96
+ a , b , c := color[1 :3 ], color[3 :5 ], color[5 :7 ]
97
+ return " #" + f (a) + f (b) + f (c)
98
+ }
60
99
```
61
100
62
101
### ** ...**
0 commit comments