Posts

Showing posts from May, 2020

05/25 周一

上午8点40多起床,今天天气很热33度最高 上午看了关于H1B的可能ban的事情 然后报税 搞了好久 到现在,吃过饭了。 2020年5月25日13:38:35 听九章上一个转行进入谷歌的讲座, 1,刷题态度 2,抽象总结 3,刷题就是一种学科 不想生活的这么卑微。 别人能做到的,我也可以! 2020年5月25日17:11:38

我是如何改变自己的人生的?

https://www.jianshu.com/p/2dc54ef75f26 我是如何改变自己的人生的? 1、跑步 2、读书 3、定目标、列清单 4、打卡 5、写作

440. Backpack III (和Backpack II的区别就是,这里元素可重复利用,而II不可重复利用)

Description 中文 English Given  n  kinds of items, and each kind of item has an infinite number available. The  i-th item has size  A[i]  and value  V[i] . Also given a backpack with size  m . What is the maximum value you can put into the backpack? You cannot divide item into small pieces. Total size of items you put into backpack can not exceed  m . Have you met this question in a real interview?    Yes Problem Correction Example Example 1: Input: A = [2, 3, 5, 7], V = [1, 5, 2, 4], m = 10 Output: 15 Explanation: Put three item 1 (A[1] = 3, V[1] = 5) into backpack. Example 2: Input: A = [1, 2, 3], V = [1, 2, 3], m = 5 Output: 5 Explanation: Strategy is not unique. For example, put five item 0 (A[0] = 1, V[0] = 1) into backpack. class Solution { public : /** * @param A: an integer array * @param V: an integer array * @param m: An integer * @ret...

550. Top K Frequent Words II

map < string , int > words; class cmp { public : bool operator () ( const string & a, const string & b) { int a_count = words[a]; int b_count = words[b]; if (a_count != b_count) return a_count > b_count; return a < b; } }; class TopK { private : set < string , cmp> q; int k; public : TopK( int k) { // initialize your data structure here this ->k = k; } void add ( string & word) { // Write your code here if (words.find(word) == words.end()) { words[word] = 1 ; } else { if (q.find(word) != q.end()) q.erase(word); words[word] += 1 ; } q.insert(word); if (q.size() > k) q.erase(--q.end()); } vector < string > topk() { // Write your code here vector < string > topk; //set<string,...

1689. k Sum III

class Solution { public : /** * @param a: the array a * @param k: the integer k * @param target: the integer target * @return: return the number of legal schemes */ int getAns ( vector < int > &a, int k, int target) { // write your code here vector < int > odds; vector < int > evens; for ( auto i : a){ if (i % 2 ){ odds.push_back(i); } else { evens.push_back(i); } } int num1 = 0 , num2 = 0 ; if (k <= odds.size()){ num1 = getNum(odds, k, target); } if (k <= evens.size()){ num2 = getNum(evens, k, target); } return num1 + num2; } int getNum ( vector < int > &a, int k, int target) { if (k > a.size()){ return 0 ; } int cnt = 0 ; dfs(a, k, target, cnt, 0 ...

570. Find the Missing Number II

class Solution { public : /** * @param n: An integer * @param str: a string with number from 1-n in random order and miss one number * @return: An integer */ int findMissing2 ( int n, string &str) { // write your code here //DFS 分隔符放在一个char还是两个 if (n <= 1 ){ return -1 ; } vector < int > visited(n, 0 ); return dfs(n, str, 0 , visited); } int dfs ( int n, string &str, int start, vector < int > &visited) { //出口 if (start >= str.size()){ vector < int > missed; for ( int i = 1 ; i <= n; i++){ if (!visited[i - 1 ]){ missed.push_back(i); } } if (missed.size() == 1 ){ return missed[ 0 ]; } else { return -1 ; } } // body if (...

05/17/2020 log

2020年5月17日11:43:40 153. Combination Sum II Find the Missing Number II  2020年5月17日12:39:49 吃饭 2020年5月17日13:40:31 回来 90. K sum II 1689. k Sum III 550. Top K Frequent Words II 545. Top k Largest Numbers II 1281. Top K Frequent Elements Kill monsters  2020年5月17日15:40:18休息 2020年5月17日18:37:22 1677. Stones 92. Backpack 562. Backpack IV 440. Backpack III