Skip to content

add: Longest Increasing Subsequence#15

Open
rossy0213 wants to merge 1 commit intomainfrom
arai60-31
Open

add: Longest Increasing Subsequence#15
rossy0213 wants to merge 1 commit intomainfrom
arai60-31

Conversation

@rossy0213
Copy link
Copy Markdown
Owner

No description provided.

}
int index = Collections.binarySearch(increasingNums, nums[i]);
if (index < 0) {
increasingNums.set(-index-1, nums[i]);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-index-1 は、~index でしたっけ?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

はい。bit演算普段あまりみないので、このままにしました。

@shining-ai
Copy link
Copy Markdown

shining-ai commented May 23, 2024

特に違和感はなく、読みやすかったです。

// Time spend: 04:20
class Solution {
public int lengthOfLIS(int[] nums) {
List<Integer> increasingNums = new ArrayList<>();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
List<Integer> increasingNums = new ArrayList<>();
var increasingNums = new ArrayList<Integer>();

長らく触ってないのでJavaの常識があまりわからないのですが、varを使った方がわかりやすい気がしました。しかしArrayListまで絞らずListにしておいた方が良いという考え方もありそうですね。

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

実際に業務で使ってる人に質問になるのですが、業務で型推論は推奨になっていますか?
(個人的には型推論利用したい派はあるが、諸事情で使っていません)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほど、右側だけで型が明確である場合、varの方が好ましいのよくわかります。
今回の場合、Listインタフェースを利用したいというのがあって、明示的に書くしかなさそうです。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants