Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: trekhleb/javascript-algorithms
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 68f3f67fcc3ea68c1ba4207db19af6b68616d0a5
Choose a base ref
..
head repository: trekhleb/javascript-algorithms
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a702f105d6c648b06fb3bdb783e947d7cf468d2c
Choose a head ref
Showing with 3 additions and 6 deletions.
  1. +3 −6 src/algorithms/sets/longest-increasing-subsequence/longestIncreasingSubsequence.js
Original file line number Diff line number Diff line change
@@ -6,11 +6,8 @@
* @return {number}
*/
export default function LongestIncreasingSubsequence(sequence) {
if (sequence.length <= 1) {
return sequence.length;
}

function lowerBound(arr, val) {
// Retrieves the smallest number greater or equal to val in sorted arr.
function upperBound(arr, val) {
let lo = 0;
let hi = arr.length;

@@ -26,6 +23,6 @@ export default function LongestIncreasingSubsequence(sequence) {
}

const lis = [];
sequence.forEach((val) => { lis[lowerBound(lis, val)] = val; });
sequence.forEach((val) => { lis[upperBound(lis, val)] = val; });
return lis.length;
}