自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(189)
  • 资源 (4)
  • 收藏
  • 关注

原创 Algorithms: Design and Analysis, Part 1, Programming Assignment #5

import heapqimport sysfname = 'dijkstraData.txt'#fname = "tc.txt"fh = open(fname)lines = [line.rstrip('\n') for line in fh]# Generate graph as a list of dictionaries.# Index of list is the ver

2016-09-06 13:55:46 638

原创 Algorithms: Design and Analysis, Part 1Problem Set #5

Correct1 / 1 points1. Consider a directed graph with distinct and nonnegative edge lengths and a source svertex. Fix a destination vertex t, and assume that the graph contains

2016-09-06 02:21:41 1236

原创 aligned memory allocation

void *aligned_alloc(size_t size, size_t align) { void *p = NULL; void *ret = NULL; p = malloc(size + align + sizeof(void *)); if (!p) return NULL; size_t offset = align - (size_t)p % alig

2016-03-22 23:23:56 491

原创 Zenefits 第一轮编程题

两道题都是所有test cases都过了,直接贴代码了/* * #1 Flip bit */int bitFlip(int arr_size, int* arr) { int no_flip = 0; int flip = 0, flip_min = 0; int i = 0; int *transform = NULL; // Vali

2016-02-29 03:14:17 380

原创 Find the Duplicate Number

class Solution {public: int findDuplicate(vector& nums) { int n = nums.size(); int s = 1, e = n; while (s < e) { int m = s + (e - s) / 2; int count

2016-02-17 14:28:55 346

原创 Find Peak Element

class Solution {public: int findPeakElement(vector& nums) { if (nums.size() < 2) return 0; int i = 1; for (; i < nums.size(); i++) { if (nums[i] < nums[i - 1])

2016-02-16 03:46:01 358

原创 Find Median from Data Stream

class MedianFinder {private: vector nums;public: // Adds a number into the data structure. void addNum(int num) { int s = 0, e = nums.size() - 1; int m; while (s

2016-02-15 13:11:23 235

原创 Longest Increasing Subsequence

DP: O(n^2)class Solution {public: int lengthOfLIS(vector& nums) { int n = nums.size(); if (n < 2) return n; int *res = new int[n]; for (int i = 0; i <

2016-02-14 15:38:23 229

原创 297. Serialize and Deserialize Binary Tree

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas

2016-02-10 17:29:33 290

原创 278. First Bad Version

class Solution {public: int firstBadVersion(int n) { int s = 1; int e = n; while (s < e) { int m = s + (e - s) / 2; if (isBadVersion(m)) {

2016-02-09 06:13:04 325

原创 328. Odd Even Linked List

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* od

2016-02-03 13:30:33 309

原创 num->string

C++:int Number = 123;string String = static_cast( &(ostringstream() str();std::string s = std::to_string(42);

2015-08-29 04:07:37 392

原创 Excel Sheet Column Number

class Solution {public: int titleToNumber(string s) { int num = 0; for (int i = 0; i < s.size(); i++) { num = num * 26 + (s[i] - 'A' + 1); } return num

2015-08-29 04:03:55 382

原创 Add Digits

class Solution {public: int addDigits(int num) { int temp = num; while(temp >= 10) { int sum = 0; while (temp) { sum += temp % 10;

2015-08-29 03:32:13 378

原创 Binary Tree Paths

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas

2015-08-29 03:27:45 321

原创 Missing Number

class Solution {public: int missingNumber(vector& nums) { int sum = 0; int num_sum = 0; int i = 0; for (; i < nums.size(); i++) { sum += i;

2015-08-28 14:42:40 344

原创 Implement Stack using Queues && Implement Queue using Stacks

Implement Stack using Queuesclass Stack {private: queueint> q;public: // Push element x onto stack. void push(int x) { queueint> t; while (!q.empty()) { t.p

2015-07-23 01:42:22 334

原创 Power of Two

class Solution {public: bool isPowerOfTwo(int n) { if (n < 1) return false; while (n > 2) { if (n % 2) return false; n = n/2; } return true

2015-07-23 01:03:22 314

原创 Maximum Gap

#1: sortO(nlogn)class Solution {public: int maximumGap(vectorint>& nums) { int n = nums.size(); if (n < 2) return 0; int res = 0; sort(nums.begin(), nums.end()

2015-07-21 14:44:16 268

原创 Summary Ranges

class Solution {public: string num2str(int num) { string res; int p = 0; long n = num; if (n < 0) { res.push_back('-'); p = 1;

2015-07-19 07:52:41 331

原创 Kth Smallest Element in a BST

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas

2015-07-17 03:04:45 295

原创 Delete Node in a Linked List

/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */void deleteNode(struct ListNode* node) { *node = *(node->next);}

2015-07-16 01:33:12 384

原创 Lowest Common Ancestor of a Binary Tree

BST:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; *

2015-07-16 01:26:12 272

原创 Palindrome Linked List

#1 using stacktime: O(n); space O(n)/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */c

2015-07-14 15:34:25 357

原创 Rotate Array

class Solution {public: void rotate(vectorint>& nums, int k) { int n = nums.size(); if (k > n) k = k % n; if (n == k || k < 1) return; vectorint> temp(nums.begin(

2015-07-09 14:20:23 375

原创 Kth Largest Element in an Array

struct mintop { bool operator() (const int& a, const int& b) const { return a>b; }};typedef priority_queue, mintop> myqueue; class Solution {public: int findKthLargest(vector&

2015-06-26 15:32:06 336

原创 Minimum Size Subarray Sum

1. O(n^2)int minSubArrayLen(int s, int* nums, int numsSize) { if (!numsSize) return 0; int i = 0, j = 1; int res = numsSize + 1; int sum = nums[0]; for (i = 0; i < numsSize; i++)

2015-06-26 15:12:41 286

原创 Binary Search Tree Iterator

/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class BSTIte

2015-06-24 15:15:53 247

原创 Min Stack

class MinStack { vector inputNum; vector minNum; public: void push(int x) { inputNum.push_back(x); int n = minNum.size(); if ((!n) || (n && x <= minNum[n - 1])

2015-06-24 14:48:02 282

原创 Invert Binary Tree

/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */clas

2015-06-24 14:25:22 455

原创 Convert a Ternary expression to a Binary tree structure

#include #include #include using namespace std;struct TreeNode { char val; TreeNode *left; TreeNode *right; TreeNode(char c): val(c), left(NULL), right(NULL) {}};// To execute C++, ple

2015-06-24 08:08:38 636

原创 c++ container with user defined compare function

1) sort by key:using function pointerbool key_compare(int a, int b){ return (a > b);}int main() { bool(*fn_cmp)(int, int) = key_compare; map m(fn_cmp);}2) sort by value:http://w

2015-06-23 16:27:23 562

原创 Majority Element

O(nlogn) -- sortvoid sort(int *nums, int s, int e) { if (s >= e) return; int p = nums[e]; int i = s, j = e; while (i < j) { while (i < j && nums[i] <= p) i++; nums[j]

2015-06-11 15:03:11 241

原创 Intersection of Two Linked Lists

用哈希表/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNo

2015-06-10 14:23:30 252

原创 Count Complete Tree Nodes

int countNodes(struct TreeNode* root) { if (!root) return 0; int left_height = 1, right_height = 1; struct TreeNode *left = root->left, *right = root->right; while(left) {

2015-06-08 13:59:47 365

原创 Repeated DNA Sequences

第一想法用map,直接存string会超内存,既然只有四个字母,用4进制数可以表示:class Solution {public: int str2num(string s) { int res = 0; for (int i = 0; i < s.size(); i++) { if (s[i] == 'A') res = re

2015-06-06 01:34:00 258

原创 Reverse Linked List

Iteration:struct ListNode* reverseList(struct ListNode* head) { if (!head) return NULL; struct ListNode *res = (struct ListNode *)malloc(sizeof(struct ListNode)); struct ListNode *c

2015-06-03 13:21:49 255

原创 ZigZag Conversion

class Solution {public: string convert(string s, int numRows) { if(numRows <= 1 || s.size() <= 1) return s; string ret; int len = s.size(); int maxgap = numRows *

2015-06-03 03:32:36 290

原创 Reverse Bits

v1:class Solution {public: uint32_t reverseBits(uint32_t n) { uint32_t res = 0; uint32_t r = 1; for (int i =0; i< 32; i++) { uint32_t temp = n & r;

2015-06-02 11:00:46 283

原创 Happy Number

class Solution {public: bool isHappy(int n) { unordered_set num; int sum = n; do { int old = sum; num.insert(old); sum = 0;

2015-05-01 09:52:31 251

Cracking the Coding Interview

important book for coding interview, concluding interview suggestions, questions and solutions

2013-01-17

Distributed and Cloud Computing

By Kai Hwang Required book for course EE532 Famous reference in this area

2013-01-17

8086汇编语言指令表

8086汇编语言指令表 包括伪指令 中断向量号等

2011-03-15

汇编语言的学生信息管理系统

汇编语言的学生管理系统,可输入并显示学生姓名 班级 学号 成绩,对成绩进行排序,求平均值

2011-03-15

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除