function twoSum(nums: number[], target: number): number[] {
let output: number[] = [];
for (let i = 0; i < nums.length; i++) {
for (let j = i + 1; j < nums.length; j++) {
if (nums[i] + nums[j] === target) {
output.push(i, j);
break;
}
}
}
return output;
}
class MinStack {
private stack: number[];
private min: number[];
constructor() {
this.stack = [];
this.min = [];
}
push(val: number): void {
if (this.min.length === 0) {
this.min.push(val);
} else {
if (val <= this.min[this.min.length - 1]) {
this.min.push(val);
}
}
this.stack.push(val);
}
pop(): void {
if (this.top() === this.min[this.min.length - 1]) {
this.min.pop();
}
this.stack.pop();
}
top(): number {
return this.stack[this.stack.length - 1];
}
getMin(): number {
return this.min[this.min.length - 1];
}
}
function reverseList(head: ListNode | null): ListNode | null {
let current = head;
let prev = null;
while (current !== null) {
let temp = current.next;
current.next = prev;
prev = current;
current = temp;
}
return prev;
}