int a =0x010;
System.out.println(a);
a =0x0010;
System.out.println(a);
a =0x0000010;
System.out.println(a);
a =0x000000000000000000000000000000000000000010;
System.out.println(a);
16진수를 표현하는 방법?
0x에 0 to f 까지 표현할수 있다. (0 -15)
<< number , >> number 연산자
비트값을 왼쪽으로 number만큼 움직여준다.
int a =8;
System.out.println(Integer.toBinaryString(a));// 001000
a = a <<2;
System.out.println(Integer.toBinaryString(a));// 100000
a = a >>2;
System.out.println(Integer.toBinaryString(a));// 001000
1을 오른쪽으로 비트 연산하게 되는경우 어떻게 나올까??
int a =1;
System.out.println(Integer.toBinaryString(a));// 00001
a = a >>5;
System.out.println(Integer.toBinaryString(a));// 0
Runtime: 15 ms, faster than 71.70% of Java online submissions for Repeated Substring Pattern.
Memory Usage: 36.5 MB, less than 100.00% of Java online submissions for Repeated Substring Pattern.
classSolution{publicbooleanrepeatedSubstringPattern(String s){//abcabcabcabcchar[] arr = s.toCharArray();// distancefor(int i=1; i<=arr.length/2; i++){if(arr.length % i !=0){continue;}boolean allSame =true;// 각 파티션
second :for(int j=i; j<arr.length; j+=i){// 파티션의 distacne 까지 비교for(int k=0; k<i; k++){if(arr[k]!= arr[j+k]){
allSame =false;break second;}}}if(allSame){returntrue;}}returnfalse;}}
head.val 과 head.next.val 을 비교해서 같으면 head.next.next를 head.next에 연결해준다.
Runtime: 0 ms, faster than 100.00% of Java online submissions for Remove Duplicates from Sorted List.
Memory Usage: 36.2 MB, less than 100.00% of Java online submissions for Remove Duplicates from Sorted List.
방문한 곳은 1 to 2로 치환하고 연결된 모든 섬의 count를 구해서 max sum을 구한다.
Runtime: 2 ms, faster than 100.00% of Java online submissions for Max Area of Island.
Memory Usage: 43.6 MB, less than 55.56% of Java online submissions for Max Area of Island.
Runtime: 7 ms, faster than 5.74% of Java online submissions for Power of Four.
Memory Usage: 34.3 MB, less than 6.67% of Java online submissions for Power of Four.
실제 코인의 이동이 아니라 코인이 없더라도 음수대로 값을 채움 ( 있는것처럼 가상의 코인을 움직인다 )
data를 채우는것은 inorder 순서로 적용
Runtime: 1 ms, faster than 87.01% of Java online submissions for Distribute Coins in Binary Tree.
Memory Usage: 37.7 MB, less than 100.00% of Java online submissions for Distribute Coins in Binary Tree.
Hi! I’m your first Markdown file in StackEdit. If you want to learn about StackEdit, you can read me. If you want to play with Markdown, you can edit me. Once you have finished with me, you can create new files by openi
1차 코드
49 ms 38.5 MB java
classSolution{public String removeDuplicates(String S){// "abbaca"if(S.length()<=1){return S;}char[] chars = S.toCharArray();
Stack<Character> stack =newStack<Character>();for(int i=0; i<chars.length; i++){if(!stack.isEmpty()){
Character cha = stack.peek();if(cha != null && cha == chars[i]){
stack.pop();continue;}}
stack.push(chars[i]);}char[] result =newchar[stack.size()];int index = stack.size()-1;while(!stack.isEmpty()){
Character last = stack.pop();
result[index--]= last;}returnnewString(result);}}
2차코드
자료구조 안쓰고 다시 한번더 풀어봐야겠다.
조건이 바로 앞뒤 2개의 character 값만 비교하는거라서 마지막 last index를 기억하는걸로
앞뒤가 서로 다를때 last index = currentIndex
앞뒤가 서로 같을때 find last index and check index ‘0’
Runtime: 4 ms, faster than 98.11% of Java online submissions for Remove All Adjacent Duplicates In String.
Memory Usage: 37.7 MB, less than 100.00% of Java online submissions for Remove All Adjacent Duplicates In String.
classSolution{public String removeDuplicates(String S){// "abbaca"if(S.length()<=1){return S;}char[] chars = S.toCharArray();int last =0;for(int i=1; i<chars.length; i++){if(last >=0&& chars[last]== chars[i]){// 같을때
chars[i]='0';
chars[last]='0';
last --;while(last >=0&& chars[last]=='0'){
last --;}}else{
last = i;}}
StringBuilder builder =newStringBuilder();for(int i=0; i<chars.length; i++){if(chars[i]!='0'){
builder.append(chars[i]);}}return builder.toString();}}
3차코드
Runtime: 3 ms, faster than 99.83% of Java online submissions for Remove All Adjacent Duplicates In String.
Memory Usage: 38.1 MB, less than 100.00% of Java online submissions for Remove All Adjacent Duplicates In String.
2차코드에서 StringBilder 제거
// "abbaca"if(S.length()<=1){return S;}char[] chars = S.toCharArray();int last =0;int resltLenth = chars.length;for(int i=1; i<chars.length; i++){if(last >=0&& chars[last]== chars[i]){// 같을때
chars[i]='0';
chars[last]='0';
last --;
resltLenth-=2;while(last >=0&& chars[last]=='0'){
last --;}}else{
last = i;}}char[] result =newchar[resltLenth];int resultIndex =0;for(int i=0; i<chars.length; i++){if(chars[i]!='0'){
result[resultIndex++]= chars[i];}}returnnewString(result);