이벤트 처리 React의 이벤트는 camelCase naming사용을 사용 Button 새 페이지를 기본동작 방지 방법 e.preventDefault(); const submit = (e : React.ChangeEvent){ e.preventDefault(); } click 조건부 렌더링 js의 조건분기처리와 같이 동작함 if(redirect === true){ return ; } return ( 다시 시도하십시오 ); 변수에 element를 할당하여 그대로 rendering하는 방법 const isLoggedIn = this.state.isLoggedIn; let button; if (isLoggedIn) { button = ; } else { button = ; } return ( {button} ..
![](http://i1.daumcdn.net/thumb/C148x148/?fname=https://blog.kakaocdn.net/dn/bZ4ZpI/btq1R75eR7C/Lc9pk1qeOinGEkCZrwlahk/img.png)
leetcode.com/problems/employee-importance/ Employee Importance - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 직원의 ID, 중요도, 직속부하직원의 ID가 포함된 직원 정보의 데이터구조가 정의된다. 어떤 직원의 중요도는 해당 직원의 중요도와 직속부하직원의 중요도의 합이다. 직원객체의 배열과, 직원ID를 argument로 넘겨주면 해당 직원의 중요도를 return 하도록 하는 문제이다., 아래와 같이 코드를 작성..
![](http://i1.daumcdn.net/thumb/C148x148/?fname=https://blog.kakaocdn.net/dn/nGMTo/btq1JUTxFxr/KQoFSv0twvJCqcX9JOO8Uk/img.png)
소유권을 갖지 않는 또다른 데이터 타입은 슬라이스이다. 슬라이스는 collection 전체가 아닌 collection의 연속된 일련의 요소들을 참조할 수 있게 함. //소유권을 갖지 않는 데이터타입. fn first_word(s : &String) -> usize { //바이트 배열로 변환 let bytes = s.as_bytes(); //iter() : 반복자 //enumerate() : 튜플형식으로 반환 //bytes의 인덱스 i, 참조값 &item for(i, &item) in bytes.iter().enumerate(){ if item == b' '{ return i; } } s.len() } pub fn run(){ let mut s = String::from("te st"); let len =..
![](http://i1.daumcdn.net/thumb/C148x148/?fname=https://blog.kakaocdn.net/dn/3Gcr6/btq1QnsNZqm/EL1MCQNbdSqTdI9hTtfbOK/img.png)
React 컴포넌트의 상태(State)와 생명주기(Lifecycle) State React는 트리형태이고, 자식 컴포넌트는 필요한 데이터를 부모 컴포넌트로부터 Props(Properties)를 받아서 사용을 할 수 있다. 하지만 Props는 읽기전용(props를 수정하면 안된다)이므로 컴포넌트 내에서 데이터의 수정이 필요한 경우에 state에서 변경할 데이터를 관리한다. 따라서 모든 컴포넌트는 state를 가지고 있다. state에서 데이터의 변경을 감지하면 데이터가 변경된 컴포넌트와 그 자식컴포넌트는 Rerendering하여 화면에 출력한다. state는 React의 컴포넌트 내에서 관리되는 일반 Javascript객체이다. 클래스 컴포넌트에서 state 키워드로 데이터를 할당하고, 데이터 변경이 필요..
leetcode.com/problems/n-repeated-element-in-size-2n-array/ N-Repeated Element in Size 2N Array - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 배열을 argument로 넘겨준다. 해당 배열 내 반복되는 숫자가 있다. 그 외의 숫자는 unique 값이다. 반복되는 숫자를 return class Solution { public: int repeatedNTimes(vector& A) { in..
leetcode.com/problems/sum-of-unique-elements/ Sum of Unique Elements - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 배열을 argument로 넘겨주면 배열 내 unique value를 찾아서 그 값들의 합을 구하는 문제이다 class Solution { public: int sumOfUnique(vector& nums) { bool flag = false; int cnt = 0; for (int i = 0..
leetcode.com/problems/how-many-numbers-are-smaller-than-the-current-number/ How Many Numbers Are Smaller Than the Current Number - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 배열을 argument로 넘겨주면 해당 배열의 각 원소별로 배열 내 해당 원소보다 작은 원소가 있다면 count하여 각 count한 결과를 배열로 만들어서 return해주는 문제임. c..