Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8804 - 两数之和 #25861

Open
JhonLandy opened this issue Mar 31, 2023 · 0 comments
Open

8804 - 两数之和 #25861

JhonLandy opened this issue Mar 31, 2023 · 0 comments
Labels
8804 answer Share answers/solutions to a question zh-CN 简体中文

Comments

@JhonLandy
Copy link

type Length<Num extends number, Len extends number[] = []>  = 
  Len['length'] extends Num 
    ? Len 
    : Length<Num, [...Len, 1]>;

type Sum<T extends any[], U extends any[]> = [...T, ...U]['length'];

type FindTarget<Num extends number, R extends number[], Target extends number> = 
  R extends [infer First extends number, ...infer Rest extends number[]]
    ? Sum<Length<Num>, Length<First>> extends Target 
      ? true
      : FindTarget<Num, Rest, Target> extends true 
        ? true
        : FindTarget<First, Rest, Target> 
    : false;

type TwoSum<T extends number[], U extends number> = T extends [infer First extends number,  ... infer Rest extends number[]]
  ? FindTarget<First, Rest, U> 
  : false
@JhonLandy JhonLandy added answer Share answers/solutions to a question zh-CN 简体中文 labels Mar 31, 2023
@github-actions github-actions bot added the 8804 label Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8804 answer Share answers/solutions to a question zh-CN 简体中文
Projects
None yet
Development

No branches or pull requests

1 participant