Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ww#1503

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
aadil42 wants to merge3 commits intoneetcode-gh:mainfromaadil42:main
Closed

ww#1503

Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions209-minimum-size-subarray-sum.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
// problem link https://leetcode.com/problems/minimum-size-subarray-sum/submissions/612844825/
// time complexity is O(n).

var minSubArrayLen = function(target, nums) {

let total = 0;
let min_length = Number.MAX_SAFE_INTEGER;
let left_pointer = 0;
for(let i = 0; i < nums.length; i++) {

total += nums[i];
while(total >= target) {
min_length = Math.min(min_length, i + 1 - left_pointer);
total -= nums[left_pointer];
left_pointer = left_pointer+1;
}
}

if(min_length == Number.MAX_SAFE_INTEGER) {
return 0;
} else {
return min_length;
}
};

30 changes: 30 additions & 0 deletionsjavascript/36-valid-sudoku.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@

// the time complexity is constant as we only going to have a 9*9 matrix.
// problem link: https://leetcode.com/problems/valid-sudoku

var isValidSudoku = function(board) {


let rows = [];
let columns = [];
let boxes = [];
for(let i = 0; i < board.length; i++) {
rows.push(new Set());
columns.push(new Set());
boxes.push(new Set());
}

for(let i = 0; i < board.length; i++) {
for(let j = 0; j < board[0].length; j++) {
const boxIndex = 3 * Math.floor(i/3) + Math.floor(j/3);
let curruntCell = board[i][j];
if(rows[i].has(curruntCell) || columns[j].has(curruntCell) || boxes[boxIndex].has(curruntCell)) return false;
if(curruntCell == '.') continue;
rows[i].add(curruntCell);
columns[j].add(curruntCell);
boxes[boxIndex].add(curruntCell);
}
}

return true;
};
23 changes: 23 additions & 0 deletionsjavascript/560-subarray-sum-equals-k.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
// Problem link https://leetcode.com/problems/subarray-sum-equals-k
// Time Complexity: O(n)


var subarraySum = function(nums, k) {



const prefixMap = {};
let totalSubArray = 0;
let ongoingSum = 0;

prefixMap[0] = 1;
for(let i = 0; i < nums.length; i++) {
ongoingSum += nums[i];
if(prefixMap[ongoingSum - k]){
totalSubArray += prefixMap[ongoingSum - k];
}
prefixMap[ongoingSum] = (prefixMap[ongoingSum] ? prefixMap[ongoingSum] + 1: 1);
}

return totalSubArray;
};

[8]ページ先頭

©2009-2025 Movatter.jp