Skip to content

Commit d99e1de

Browse files
committed
documentation
1 parent 7af7ded commit d99e1de

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

Diff for: src/java/BinaryArithmetic.java

+16-17
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
import java.util.Arrays;
22

3-
// // "101" "010" -> "111"
4-
// // "101" "011" -> "1000"
5-
3+
/**
4+
*
5+
* Location https://coderpad.io/WGT7MX76
6+
*
7+
* Example showing how to work with two arrays which need
8+
* to be aligned at their ends (not starts), and where the
9+
* result of the current might affect the next.
10+
*
11+
* Useful for:
12+
* - binary arithmetic ("101" "010" -> "111" OR "101" "011" -> "1000")
13+
* - iterating through arrays of json where the following item might affect the result of the previous (a carry behavior)
14+
*/
615
public class BinaryArithmetic {
716

817
/**
918
* minimal time is going to be max length of one of the string
10-
* x2 because of initialization and conversion to string
19+
* x3 because of
20+
* - initialization and
21+
* - actual computation loop
22+
* - conversion to string
1123
*/
1224
static String addBinaryStrings(String a, String b) throws Exception {
1325
if (a == null) {
@@ -68,8 +80,6 @@ static String addBinaryStrings(String a, String b) throws Exception {
6880
}
6981
}
7082

71-
// previousResult = current;
72-
// Convert array of ints into its string value
7383
String asString = "";
7484
if (previousResult == 1) {
7585
asString += "1";
@@ -95,15 +105,4 @@ static int addChar(char a, char b) throws Exception {
95105
return 0;
96106
}
97107

98-
99-
100-
// // something(current, positionofcarry){
101-
102-
// // if(pofsitionofcarry!= null){
103-
// // done
104-
// // }
105-
// // something(positionofcarry, psotionofcarry--)
106-
107-
// // }
108-
//
109108
}

0 commit comments

Comments
 (0)