문제풀이 2021 02 02
2021.02.02 연습
- 사용언어 : java
class Solution {
public int[] decode(int[] encoded, int first) {
int[] result = new int[encoded.length+1];
result[0] = first;
for (int i = 0; i <result.length-1; i++) {
result[i+1] = encoded[i] ^ result[i];
}
return result;
}
}
- XOR 연산 : 입력값 중 하나만
true
일 때true
를 리턴해준다.
Runtime: 1 ms, faster than 100.00% of Java online submissions for Decode XORed Array. Memory Usage: 39.6 MB, less than 92.63% of Java online submissions for Decode XORed Array.
class Solution {
public boolean arrayStringsAreEqual(String[] word1, String[] word2) {
StringBuilder w1 = new StringBuilder();
StringBuilder w2 = new StringBuilder();
for (String s1 : word1) {
w1.append(s1);
}
for (String s2 : word2) {
w2.append(s2);
}
return (w1.toString()).equals(w2.toString());
}
}
Runtime: 1 ms, faster than 73.59% of Java online submissions for Check If Two String Arrays are Equivalent. Memory Usage: 38.7 MB, less than 23.14% of Java online submissions for Check If Two String Arrays are Equivalent.