3/19 leetcode 문제 풀이
사전 학습!
Set 객체는 자료형에 관계 없이 원시값과 객체 참조 모두 유일한 값을 저장할 수 있다.
var set = Set();
set.add(1); // Set {1}
set.has(1); // true
set.delete(1); // 1 delete
연결 리스트정리
링크텍스트
#141
참고: 승지니어
var hasCycle = function(head) {
let walker = head;
let runner = head;
while(runner !=null){
runner = runner.next;
if(runner!=null){
runner = runner.next;
walker = walker.next;
if(runner == walker) break;
}else break;
}
if(runner==null) return false;
else return true;
};
#155
참고: 승지니어 & https://leetcode.com/problems/min-stack/discuss/204269/javascript
/**
- initialize your data structure here.
*/
var MinStack = function() {
this.stack= [];
};
/**
- @param {number} val
- @return {void}
*/
MinStack.prototype.push = function(val) {
let min = this.stack.length === 0? val: this.stack[this.stack.length -1].min;
this.stack.push({val:val, min: Math.min(min,val)});
};
/**
- @return {void}
*/
MinStack.prototype.pop = function() {
if(this.stack.length > 0){
this.stack.pop();
}
};
/**
- @return {number}
*/
MinStack.prototype.top = function() {
if(this.stack.length > 0){
return this.stack[this.stack.length-1].val;
}
};
/**
- @return {number}
*/
MinStack.prototype.getMin = function() {
if(this.stack.length>0){
return this.stack[this.stack.length-1].min;
}
};
/**
- Your MinStack object will be instantiated and called as such:
- var obj = new MinStack()
- obj.push(val)
- obj.pop()
- var param_3 = obj.top()
- var param_4 = obj.getMin()
*/
#160
var getIntersectionNode = function(headA, headB) {
let a = headA;
let b = headB;
while(a != null && b != null){
a = a.next;
b = b.next;
if(a === b){
return a;
}
if(a === null){
a = headB;
}
if(b === null){
b = headA;
}
}
return a ;
};
참고자료
-javascript Set() 객체
링크텍스트
-linked list
링크텍스트
Author And Source
이 문제에 관하여(3/19 leetcode 문제 풀이), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@jeongyunjang/319-leetcode-문제-풀이-vonyxnsn저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)