My Blog List

Wednesday, May 31, 2017

The clean coder를 읽고 난 소감

책을 읽고 난 다음 머가 남았는가 회상해본다.

1. 하루에 8시간은 회사업무를 하고 2시간은 나를 위해서 사용한다.
2. 매일 쉬운문제를 풀어서 손과 머리 두뇌,, 연습해라,
3. 일정잡을때 약속을 할때 말을 조심해야한다.

머 이정도 된것 같다.

TDD 도 중요하게 생각하는것 같고.

약간 자기 개발서 같은 느낌이다. ㅡ.ㅡ;

그닥 나에게 도움된 책은 아닌듯.

are Simmilar

https://codefights.com/arcade/intro/level-4/xYXfzQmnhBvEKJwXP

my solution is  below

what i focus on is when difference is 0 or 2


public static boolean areSimilar(int[] a, int[] b) {

  int difference= 0; 
  int [] p = new int[2];
  int pos = 0;
  
  for (int i = 0; i < a.length; i++) {  
   
   if(a[i] != b[i]){
    if(difference==2){
     return false;
    }    
    p[pos++] = i;
    difference++;
   }
  }
  
  return difference ==0 || (difference ==2 && (a[p[0]] == b[p[1]] && a[p[1]] == b[p[0]]));
 }

Wednesday, May 17, 2017

codefights smooth sailing ( CommonCharacterCount)

https://codefights.com/arcade/intro/level-3/JKKuHJknZNj4YGL32

public static int commonCharacterCount(String s1, String s2) {
  int sum = 0;
  
  char[] as= s1.toCharArray();
  char[] bs= s2.toCharArray();
  
  int[] ias = new int[126];
  int[] ibs = new int[126];
  
  for (int i = 0; i < as.length; i++) {
   ias[(int)as[i]]++;
  }
  
  for (int i = 0; i < bs.length; i++) {
   ibs[(int)bs[i]]++;
  }
  
  for (int i = 0; i < ibs.length; i++) {
   sum += Math.min(ias[i], ibs[i]);
  }
  return sum;
 }


Given two strings, find the number of common characters between them.
Example
For s1 = "aabcc" and s2 = "adcaa", the output should be
commonCharacterCount(s1, s2) = 3.
Strings have 3 common characters - 2 "a"s and 1 "c".
Input/Output
  • [time limit] 3000ms (java)
  • [input] string s1
    A string consisting of lowercase latin letters a-z.
    Guaranteed constraints:
    1 ≤ s1.length ≤ 15.
  • [input] string s2
    A string consisting of lowercase latin letters a-z.
    Guaranteed constraints:
    1 ≤ s2.length ≤ 15.
  • [output] integer

Monday, May 15, 2017

codefights matrixElementsSum easy

https://codefights.com/arcade/intro/level-2/xskq4ZxLyqQMCLshr/description

my answer is 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int matrixElementsSum(int[][] matrix) {
int sum=0;
 
    for(int i=0; i<matrix[0].length; i++){
        sub:
        for(int y=0; y<matrix.length;y++)    {
            if(matrix[y][i] == 0){
                    break sub;
            }else{
                sum+= matrix[y][i];
            }
        }
    }
    
    return sum;
}
 
cs

After becoming famous, CodeBots decided to move to a new building and live together. The building is represented by a rectangular matrix of rooms, each cell containing an integer - the price of the room. Some rooms are free (their cost is 0), but that's probably because they are haunted, so all the bots are afraid of them. That is why any room that is free or is located anywhere below a free room in the same column is not considered suitable for the bots.
Help the bots calculate the total price of all the rooms that are suitable for them.
Example
For
matrix = [[0, 1, 1, 2], 
          [0, 5, 0, 0], 
          [2, 0, 3, 3]]
the output should be
matrixElementsSum(matrix) = 9.
Here's the rooms matrix with unsuitable rooms marked with 'x':
[[x, 1, 1, 2], 
 [x, 5, x, x], 
 [x, x, x, x]]
Thus, the answer is 1 + 5 + 1 + 2 = 9.