代码改变世界

leetcode - N-Queens II

2013-11-22 23:09 by 张汉生, 168 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 void generateResults(int & rlt, int n, int index, bool * flag1, bool * flag2, bool* flag3){ 4 for (int i=0; i<n; i++){ 5 int j = index+i; 6 int k = index-i+n-1; 7 if (flag1[i] || flag2[j] || flag3[k]){ 8 continue; 9 }10 ... 阅读全文

leetcode - N-Queens

2013-11-22 23:01 by 张汉生, 198 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 void generateResults(vector > &rlts, int n, int index, int * cur, bool * flag1, bool * flag2, bool* flag3){ 4 for (int i=0; i rlt;16 for (int p=0; p > solveNQueens(int n) {35 // IMPORTANT: Please reset any member data you declared, as36 // the... 阅读全文

leetcode - Pow(x, n)

2013-11-20 21:53 by 张汉生, 196 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 double pow(double x, int n) { 4 // IMPORTANT: Please reset any member data you declared, as 5 // the same Solution instance will be reused for each test case. 6 if (x1)14 return 0;15 if (n == INT_MAX && x < 1)16 ... 阅读全文

leetcode - LRU Cache

2013-11-20 21:37 by 张汉生, 156 阅读, 0 推荐, 收藏, 编辑
摘要:1 struct Rec{ 2 int key; 3 int value; 4 }; 5 6 class LRUCache{ 7 private: 8 Rec * buffer; 9 int size;10 int curSize;11 public:12 LRUCache(int capacity) {13 size = capacity;14 buffer = new Rec[size];15 curSize = 0;16 }17 ~LRUCache(){18 ... 阅读全文

leetcode - Valid Number

2013-11-20 15:54 by 张汉生, 195 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 bool isInt(const char * s, int start, int end){ 4 if (end '9')12 return false;13 }14 return true;15 }16 bool isDouble(const char * s, int start, int end){17 if (start = start && s[end] == ' ')39 e... 阅读全文

leetcode - Insertion Sort List

2013-11-20 14:41 by 张汉生, 166 阅读, 0 推荐, 收藏, 编辑
摘要:1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), next(NULL) {} 7 * }; 8 */ 9 class Solution {10 public:11 ListNode *insertionSortList(ListNode *head) {12 // IMPORTANT: Please reset any me... 阅读全文

leetcode - Sort List

2013-11-20 14:26 by 张汉生, 163 阅读, 0 推荐, 收藏, 编辑
摘要:1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), next(NULL) {} 7 * }; 8 */ 9 class Solution {10 public:11 ListNode * mergeList(ListNode * left, ListNode * right){12 ListNode * head = NULL... 阅读全文

leetcode - Sqrt(x)

2013-11-19 16:32 by 张汉生, 172 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 int sqrt(int x) { 4 // IMPORTANT: Please reset any member data you declared, as 5 // the same Solution instance will be reused for each test case. 6 if (x<=0) 7 return 0; 8 int right = x; 9 int left = 1;10 ... 阅读全文

leetcode - Simplify Path

2013-11-11 23:09 by 张汉生, 148 阅读, 0 推荐, 收藏, 编辑
摘要:1 class Solution { 2 public: 3 string simplifyPath(string path) { 4 // IMPORTANT: Please reset any member data you declared, as 5 // the same Solution instance will be reused for each test case. 6 vector names; 7 int len = path.length(); 8 string token = ... 阅读全文

leetcode - Partition List

2013-11-11 22:44 by 张汉生, 145 阅读, 0 推荐, 收藏, 编辑
摘要:1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * ListNode *next; 6 * ListNode(int x) : val(x), next(NULL) {} 7 * }; 8 */ 9 class Solution {10 public:11 ListNode *partition(ListNode *head, int x) {12 // IMPORTANT: Please reset any mem... 阅读全文
上一页 1 2 3 4 5 6 7 8 ··· 16 下一页