- 博客(32)
- 资源 (3)
- 收藏
- 关注
原创 (一)关于对象
在C语言中,语言本身并没有建立数据和函数之间的关联性,所以C语言被称为是面向过程(procedural)的。C++有允许用户进行自行定义的抽象数据类型(ADT),这类语言被称为面向对象的语言。 那么第一个问题来了,加上封装之后,布局成本有没有增加? 以以下一个类Point3d为例来分析。class Point3d{public: Point3d(float x = 0.
2016-07-27 21:39:05 298
原创 Data语意学里的一些问题
今天和小伙伴讨论了第三章data语意学的指一些的知识,感觉很有必要总结一下,似乎不总结知识就会溜走,所以冒夜写一下吧。 首先看这样的一个继承的例子: class X{ };class Y: public virtualX { };class Z: public virtualX { };class A: public Y,publicZ { }; 分别对X Y Z A取sizeof,
2016-07-18 11:35:18 820
原创 210. Course Schedule II
There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as
2016-07-05 16:44:21 246
原创 207. Course Schedule
There are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as
2016-07-05 16:25:14 188
原创 200. Number of Islands
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. You may assu
2016-07-05 14:50:34 189
原创 133. Clone Graph
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.OJ's undirected graph serialization:Nodes are labeled uniquely.We use # as a separator for ea
2016-07-05 10:16:36 368
原创 199. Binary Tree Right Side View
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following binary tree, 1
2016-07-05 09:05:11 203
原创 129. Sum Root to Leaf Numbers
Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the tota
2016-07-05 08:10:43 184
原创 124. Binary Tree Maximum Path Sum
Given a binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree along the parent-child connections. The
2016-07-04 22:51:03 233
原创 257. Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]题意:返回二叉树的
2016-07-04 21:44:01 227
原创 117. Populating Next Right Pointers in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant
2016-07-04 17:24:04 160
原创 116. Populating Next Right Pointers in Each Node
Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next right node.
2016-07-04 16:38:06 151
原创 114. Flatten Binary Tree to Linked List
Given a binary tree, flatten it to a linked list in-place.For example,Given 1 / \ 2 5 / \ \ 3 4 6The flattened tree should look like: 1
2016-07-04 16:19:19 207
原创 98. Validate Binary Search Tree
Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than the node's key.Th
2016-07-04 15:41:15 168
原创 318. Maximum Product of Word Lengths
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will contain only lower case le
2016-07-04 14:58:14 171
原创 260. Single Number III
Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:Given
2016-07-04 11:27:25 182
原创 201. Bitwise AND of Numbers Range
Given a range [m, n] where 0 For example, given the range [5, 7], you should return 4.题意:返回m到n之间所有数的与思路:低位有不同,则低位与的结果为0,去除低位的不同,直到m n相等的时候,说明此后到位都是相同的。返回这个结果即可。class Solution {public:
2016-07-04 11:03:46 176
原创 137. Single Number II
Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it without u
2016-07-04 09:55:34 163
原创 324. Wiggle Sort II
Given an unsorted array nums, reorder it such that nums[0] nums[2] .Example:(1) Given nums = [1, 5, 1, 1, 6, 4], one possible answer is [1, 4, 1, 5, 1, 6]. (2) Given nums = [1, 3, 2, 2, 3
2016-07-03 16:55:14 157
原创 179. Largest Number
Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the largest formed number is 9534330.Note: The result may be ve
2016-07-03 16:24:49 168
原创 241. Different Ways to Add Parentheses
Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are+, - and *.Example 1I
2016-07-03 11:03:46 170
原创 345. Reverse Vowels of a String
Write a function that takes a string as input and reverse only the vowels of a string.Example 1:Given s = "hello", return "holle".Example 2:Given s = "leetcode", return "leotcede".题意:把
2016-07-02 23:09:48 269
原创 151. Reverse Words in a String
Given an input string, reverse the string word by word.For example,Given s = "the sky is blue",return "blue is sky the".Update (2015-02-12):For C programmers: Try to solve it in-place
2016-07-02 22:51:53 256
原创 344. Reverse String
Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".题意:实现string的逆置。思路:直接实现。class Solution {public: string reverseStr
2016-07-02 22:16:16 137
原创 319. Bulb Switcher
There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning off
2016-07-02 22:06:33 160
原创 67. Add Binary
Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".题意:两个二进制的字符串求和。思路:逆序,从低位开始加和。进位思路,类似乘法。class Solution {public: string addBin
2016-07-02 21:38:44 154
原创 148. Sort List
Sort a linked list in O(n log n) time using constant space complexity.题意:给链表进行排序。思路:归并排序。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next;
2016-07-02 20:56:38 180
原创 143. Reorder List
Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given {1,2,3,4}, reorder it to
2016-07-02 19:50:40 142
原创 142. Linked List Cycle II
Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Note: Do not modify the linked list.Follow up:Can you solve it without using extra space?题意
2016-07-01 17:12:54 167
原创 141. Linked List Cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?题意:检测一个链表是否有环,要求不使用额外的空间。思路:设置两个指针,一个走的快一次移动两步,一个走得慢一次移动1步,如果两个指针未结束前相遇,那么有环,否则走
2016-07-01 16:37:08 148
原创 109. Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST.题意:把一个排好序的链表转化为二叉排序树。思路:利用引用来做,head在递归过程中只维持一份,随着递归路径的进行head会发生变化。复杂度为O(n)。这样的劣势在于构建完之后
2016-07-01 15:56:28 190
原创 92. Reverse Linked List II
Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m, n satisfy t
2016-07-01 10:15:31 134
CUDA编程指南
2016-04-18
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人