Saturday, October 6, 2018
오랫만에 풀어본 문제 serialized and desirialize
https://leetcode.com/problems/serialize-and-deserialize-binary-tree/description/
dfs 로 길을 갔었고 가는 곳 마다 흔적을 남겼고 다시 그 흔적을 따라 deserialized를 하면 풀리는 문제
Monday, September 17, 2018
async sync
sync와 async
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263// sync
@Test
public void zipTestSync(){
long start = System.currentTimeMillis();
// 비행편 가져오기
Flight flight = lookupFlight("a");
// 승객가져오기
Passenger passenger = findPassanger("person");
// 티켓 가져오기
Ticket ticket = getTicket(flight, passenger);
// 티켓 메일 보내기
sendEmail(ticket);
System.out.println(System.currentTimeMillis() - start);
}
// async
@Test
public void zipTestSingle(){
long start = System.currentTimeMillis();
// 비행기 lazyloading
Single<Flight> flight = Single.defer(() -> Single.just(lookupFlight("a")))
.subscribeOn(Schedulers.io());
// 승객 lazyloading
Single<Passenger> passenger = Single.defer(() ->Single.just(findPassanger("person")))
.subscribeOn(Schedulers.io());
// 비행기에서 승객을 zip으로 묶어서 다 로딩이된후 티켓을 가져오는데 .toBlocking으로 기다린다.
flight.zipWith(passenger, (f, p) -> getTicket(f, p))
.toBlocking()
.value().getFlightName();
System.out.println(System.currentTimeMillis()- start);
}
private Flight lookupFlight(String name) {
try {
Thread.currentThread().sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("lokkupFlight : " + name);
return Flight.builder().name(name).build();
}
private Passenger findPassanger(String name){
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("findPassanger");
return Passenger.builder().name(name).build();
}
private Ticket getTicket (Flight flight, Passenger passenger){
return Ticket.builder().flightName(flight.name).passengerName(passenger.getName()).build();
}
private void sendEmail(Ticket ticket){
System.out.println("sending ");
}
Friday, August 10, 2018
8개월간 클라이밍으로 인한 신체 변화
인증샷이다
지금부터 8개월전 클라이밍을 시작했고 지금 와서 인증샷을 찍었다
[변화]
몸무게 78kg -> 76kg -2kg
근육 30.1kg -> 31kg +1kg
체지방 24.7 -> 21.1 -3.3kg
체지방률 31.5% -> 27.7%
종합 점수 : 64점 -> 70점
엄청난 변화인것 같다.
클라이밍을 1년정도는 더 할 생각이 있는데
그때는 75점은 넘지 않을까 기대되네.
Thursday, July 5, 2018
regular expression 사용 예제
오랫만에 패턴 매칭해서 결과값 구하는것 찾음.
regular expression은 내가 짠거는 쉬운데 남이 짠거는 잘 안읽힘. ㅠ
T10 / name / AB12345
regular expression은 내가 짠거는 쉬운데 남이 짠거는 잘 안읽힘. ㅠ
Pattern p = Pattern.compile("(([a-zA-Z][0-9][0-9]?)\\s*[\\/]\\s*.{3}\\s*[\\/]\\s*)");Matcher m = p.matcher(line); while(m.find())
T10 / name / AB12345
Sunday, March 18, 2018
line encoding
I solved this problem with for
somebody solved this one with reguar expression
Given a string, return its encoding defined as follows:
somebody solved this one with reguar expression
Given a string, return its encoding defined as follows:
- First, the string is divided into the least possible number of disjoint substrings consisting of identical characters
- for example,
"aabbbc"
is divided into["aa", "bbb", "c"]
- for example,
- Next, each substring with length greater than one is replaced with a concatenation of its length and the repeating character
- for example, substring
"bbb"
is replaced by"3b"
- for example, substring
- Finally, all the new strings are concatenated together in the same order and a new string is returned.
Example
For
s = "aabbbc"
, the output should belineEncoding(s) = "2a3bc"
.
Input/Output
- [execution time limit] 3 seconds (java)
- [input] string sString consisting of lowercase English letters.Guaranteed constraints:
4 ≤ s.length ≤ 15
. - [output] stringEncoded version of
s
.
[Java] Syntax Tips
// Prints help message to the console
// Returns a string
//
// Globals declared here will cause a compilation error,
// declare variables inside the function instead!
String helloWorld(String name) {
System.out.println("This prints to the console when you Run Tests");
return "Hello, " + name;
}
Sunday, March 4, 2018
codefights darkwilderness
My answer is O(n) and just use Math.abs
Given the positions of a white
bishop
and a black pawn
on the standard chess board, determine whether the bishop can capture the pawn in one move.
The bishop has no restrictions in distance for each move, but is limited to diagonal movement. Check out the example below to see how it can move:


Example
- For
bishop = "a1"
andpawn = "c3"
, the output should bebishopAndPawn(bishop, pawn) = true
. - For
bishop = "h1"
andpawn = "h3"
, the output should bebishopAndPawn(bishop, pawn) = false
.
Input/Output
- [execution time limit] 3 seconds (java)
- [input] string bishopCoordinates of the white bishop in the chess notation.
- [input] string pawnCoordinates of the black pawn in the same notation.
- [output] boolean
true
if the bishop can capture the pawn,false
otherwise.
[Java] Syntax Tips
// Prints help message to the console
// Returns a string
//
// Globals declared here will cause a compilation error,
// declare variables inside the function instead!
String helloWorld(String name) {
System.out.println("This prints to the console when you Run Tests");
return "Hello, " + name;
}
Sunday, November 26, 2017
버킷리스트
생각나는대로 버킷리스트를 작성하려고 한다.
1. 첫째아들과 둘째아들과 실내클라이밍 배우기
2. 첫째아들과 둘째아들과 여의도, 춘천 캠핑
3. 러시아 횡단열차타서 유럽으로 가기
4. 미국 라스베가스 한번더 놀러가기
5. 와이프랑 에펠타워 가기
6. 부모님 모시고 펜션 놀러가서 고기 구워먹기
7. 암벽등반 도전해보기.
ㅎㅎㅎ
1. 첫째아들과 둘째아들과 실내클라이밍 배우기
2. 첫째아들과 둘째아들과 여의도, 춘천 캠핑
3. 러시아 횡단열차타서 유럽으로 가기
4. 미국 라스베가스 한번더 놀러가기
5. 와이프랑 에펠타워 가기
6. 부모님 모시고 펜션 놀러가서 고기 구워먹기
7. 암벽등반 도전해보기.
ㅎㅎㅎ
Subscribe to:
Posts (Atom)