Problem Solving/리트코드(leetcode) (29) 썸네일형 리스트형 Single Number class Solution { public: int singleNumber(vector& nums) { int answer = nums[0]; for(int i = 1; i Count Primes class Solution { public: int countPrimes(int n) { bool arr[5000001]; fill_n(arr, 5000001, 1); int count = 0; for(int i = 2; i [Leetcode/C++] 66. Plus One class Solution { public: vector plusOne(vector& digits) { int carry = 1; for(int i = digits.size()-1; i >= 0; i--) { if(digits[i] == 9 && carry == 1) { digits[i] = 0; carry = 1; } else { digits[i] += carry; carry = 0; } } if(digits[0] == 0) digits.insert(digits.begin(), 1); return digits; } }; 논리설계 수업 때 2진수 ADDER를 만들던게 생각나는 문제였습니다. carry(올림 숫자)를 추가해 9일 때 올림 숫자를 받게 되면 올림 숫자는 그대로 가져가고 자리수는 0으로 바꿔주.. Pascal's Triangle class Solution { public: vector generate(int numRows) { vector arr; vector rows; for(int i = 0; i [Leetcode/C++] 455. Assign Cookies class Solution { public: int findContentChildren(vector& g, vector& s) { sort(g.begin(), g.end()); sort(s.begin(), s.end()); int count = 0; for(int i = 0 ; i < g.size(); i++) { for(int j = 0 ; j < s.size(); j++) { if(g[i] 이전 1 2 3 4 다음