We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4212d3c commit 1da3db3Copy full SHA for 1da3db3
Easy/Similar RGB Color.java
@@ -0,0 +1,16 @@
1
+class Solution {
2
+ public String similarRGB(String color) {
3
+ StringBuilder simlarColor = new StringBuilder();
4
+ simlarColor.append("#");
5
+ for (int i = 1; i < 6; i += 2) {
6
+ simlarColor.append(findClosestColor(color.substring(i, i + 2)));
7
+ }
8
+ return simlarColor.toString();
9
10
+
11
+ private String findClosestColor(String section) {
12
+ int num = Integer.parseInt(section, 16);
13
+ int roundedValue = Math.round((float) num / 17);
14
+ return Integer.toHexString(roundedValue).repeat(2);
15
16
+}
0 commit comments