next I will try graph arcade. I think graph problem is more difficult than intro.

https://leetcode.com/problems/longest-substring-with-at-least-k-repeating-characters/
Runtime: 3 ms, faster than 77.01% of Java online submissions for Longest Substring with At Least K Repeating Characters.
class Solution {
int max;
public int longestSubstring(String s, int k) {
max =0;
if(k>s.length()){return 0;}
findMax(s, k);
return max;
}
public void findMax(String s, int k){
int arr[] = new int['z' - 'a' +1];
// setting
for(int i=0; i<s.length(); i++){
int index = s.charAt(i) -'a';
arr[index]++;
}
// 전부다 k보다 더 큰 수가 나오는 경우는 max값을 갱신
if(allEqualOrBigger(arr, k)){
max = Math.max(max, s.length());
}else{
char[] str= new char[s.length()];
for(int i=0; i<s.length(); i++){
int index = s.charAt(i) -'a';
if(arr[index] == 0 ){
continue;
}else if(arr[index] >=k){ //
str[i] = s.charAt(i);
}else{
str[i] = ',';
}
}
String[] subs = new String(str).split(",");
for(int i=0; i<subs.length; i++){
if(subs[i].length() <= max){
continue;
}
findMax(subs[i], k);
}
}
}
public boolean allEqualOrBigger(int arr[], int k){
for(int i=0; i< arr.length; i++){
if(arr[i] >0 && arr[i]<k){
return false;
}
}
return true;
}
}
https://leetcode.com/problems/flatten-nested-list-iterator/discuss/?orderBy=recent_activity
Runtime: 6 ms, faster than 42.53% of Java online submissions for Flatten Nested List Iterator.
public class NestedIterator implements Iterator<Integer> {
Stack<NestedInteger> stack = new Stack<NestedInteger>();
public NestedIterator(List<NestedInteger> nestedList) {
for(int i= nestedList.size() -1; i>=0; i--){
stack.push(nestedList.get(i));
}
}
@Override
public Integer next() {
return stack.pop().getInteger();
}
@Override
public boolean hasNext() {
while(stack.size()>0){
NestedInteger nestedInteger = stack.peek();
if(nestedInteger.isInteger()){
return true;
}else{
nestedInteger = stack.pop();
List<NestedInteger> list = nestedInteger.getList();
for(int i=list.size()-1; i>=0; i--){
//stack.push(list.get(i));
if(list.get(i).isInteger()){
stack.push(list.get(i));
}else{
if(list.get(i).getList().size()>0){
stack.push(list.get(i));
}
}
}
}
}
return false;
}
}
link TypeScript-Handbook/Basic Types.md at master · Microsoft/TypeScript-Handbook · GitHub
열거 형을 제공한다.
1let isDone: boolean = false;
1234let decimal: number = 6
let hex: number = 0xf00d;
let binary: number = 0b1010;
let octal: number = 0O744
12let color: string= "blue";
color = 'red';
12345let fullName: string = `Bob Bobbington`;
let age: number = 37;
let sentence: string = `Hello, my name is ${ fullName }.
I'll be ${ age + 1 } years old next month.`;
123var fullName = "Bob Bobbington";
var age = 37;
var sentence = "Hello, my name is " + fullName + ".\n\nI'll be " + (age + 1) + " years old next month.";
123let list: number[] = [1, 2, 3];
let list: Array<number> = [1, 2, 3];
123456// Declare a tuple type
let x: [string, number];
// Initialize it
x = ["hello", 10]; // OK
// Initialize it incorrectly
x = [10, "hello"]; // Error
123enum Color {Red, Green, Blue}
let c: Color = Color.Green;
123456789var Color;
(function (Color) {
Color[Color["Red"] = 0] = "Red";
Color[Color["Green"] = 1] = "Green";
Color[Color["Blue"] = 2] = "Blue";
})(Color || (Color = {}));
var c = Color.Green;
{0: "Red", 1: "Green", 2: "Blue", Red: 0, Green: 1, Blue: 2}
1234567891011let notSure: any = 4;
notSure = "maybe a string instead";
notSure = false; // okay, definitely a boolean
// 오브젝트는 할당만 가능하고 임의의 메소드를 사용 못한다.
let notSure: any = 4;
notSure.ifItExists(); // okay, ifItExists might exist at runtime
notSure.toFixed(); // okay, toFixed exists (but the compiler doesn't check)
let prettySure: Object = 4;
prettySure.toFixed(); // Error: Property 'toFixed' doesn't exist on type 'Object'.
123let list: any[] = [1, true, "free"];
list[1] = 100;
12345function warnUser(): void {
console.log("This is my warning message");
}
let unusable: void = undefined;
12345// Not much else we can assign to these variables!
let u: undefined = undefined;
let n: null = null;
// subtype 증명
123456789101112131415// Function returning never must have unreachable end point
function error(message: string): never {
throw new Error(message);
}
// Inferred return type is never
function fail() {
return error("Something failed");
}
// Function returning never must have unreachable end point
function infiniteLoop(): never {
while (true) {
}
}
123456789declare function create(o: object | null): void;
create({ prop: 0 }); // OK
create(null); // OK
create(42); // Error
create("string"); // Error
create(false); // Error
create(undefined); // Error
12345678// angle-bracket
let someValue: any = "this is a string";
let strLength: number = (<string>someValue).length;
// as syntax
let someValue: any = "this is a string";
let strLength: number = (someValue as string).length;
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 ");
}
Pattern p = Pattern.compile("(([a-zA-Z][0-9][0-9]?)\\s*[\\/]\\s*.{3}\\s*[\\/]\\s*)");Matcher m = p.matcher(line); while(m.find())
"aabbbc"
is divided into ["aa", "bbb", "c"]
"bbb"
is replaced by "3b"
s = "aabbbc"
, the output should belineEncoding(s) = "2a3bc"
.4 ≤ s.length ≤ 15
.s
.// 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;
}
bishop
and a black pawn
on the standard chess board, determine whether the bishop can capture the pawn in one move.bishop = "a1"
and pawn = "c3"
, the output should bebishopAndPawn(bishop, pawn) = true
.bishop = "h1"
and pawn = "h3"
, the output should bebishopAndPawn(bishop, pawn) = false
.true
if the bishop can capture the pawn, false
otherwise.// 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;
}