You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Just solved it using a sliding window technique, maybe you'd like to add it as another example of a valid solution.
public static int smallestSub(int[] a, int k) {
int l = 0, r = 1, sum = a[l];
while (r < a.length) {
sum += a[r++];
while (sum > k) {
sum -= a[l++];
}
}
return r - l + 1;
}
היעילות זמן ריצה היא: O(n) שכן אנחנו עוברים על המערך פעם אחת בלבד, והלולאה הפנימית משמשת רק על מנת להקטין את גודל "החלון" ולקדם את l.
מבחינת זיכרון כל המשתנים הם קבועים ולכן הסיבוכיות היא O(1).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Just solved it using a sliding window technique, maybe you'd like to add it as another example of a valid solution.
Beta Was this translation helpful? Give feedback.
All reactions