摘要:
class Solution {public: int canCompleteCircuit(vector &gas, vector &cost) { // Note: The Solution object is instantiated only once and is reused by each test case. if (gas.size() != cost.size()) return -1; vector diff; int total = 0; for (int i = 0; i < ... 阅读全文
摘要:
1 /** 2 * Definition for singly-linked list with a random pointer. 3 * struct RandomListNode { 4 * int label; 5 * RandomListNode *next, *random; 6 * RandomListNode(int x) : label(x), next(NULL), random(NULL) {} 7 * }; 8 */ 9 class Solution {10 public:11 RandomListNode *copyRa... 阅读全文
摘要:
1 class Solution { 2 public: 3 int singleNumber(int A[], int n) { 4 // Note: The Solution object is instantiated only once and is reused by each test case. 5 if (n == 0) return 0; 6 7 int bit[32]; 8 int result = 0; 9 10 for (int i = 0; i ... 阅读全文
摘要:
DP+剪枝class Solution {public: bool dfs(string s, unordered_set &dict, unordered_set &unmatch, int maxLen, vector &result,string path){ if (s.size() == 0){ path.pop_back(); result.push_back(path); return true; } bool flag = f... 阅读全文
摘要:
DP + 剪枝 1 class Solution{ 2 public: 3 bool wordBreakHelper(string s, unordered_set &dict,unordered_set &unmatch, int maxLength) { 4 if(s.length() == 0) return true; 5 6 for(int i = 1; i &dict) {20 21 if(s.size() == 0) return true;22 unordered... 阅读全文