- 博客(7)
- 收藏
- 关注
原创 翁恺C笔记|动态内存分配
【题引子】 C99可以用变量定义数组的大小,其他不可以。 int number; scanf("%d",&number) //C99中可以这么干 int a[number];所以如果我们在定义之前不知道需要多少空间,应该怎样申请空间呢? 【动态内存分配】 动态内存分配:int* a=(int*)malloc(n*sizeof(int)) malloc函数原型: #inc
2016-08-13 16:37:29 926
原创 翁恺C笔记|指针
【指针应用场景】 1.函数需要返回多个值,其中一些值可通过指针返回。传入的指针参数其实是需要保存带回结果的变量; 例程: #include #include void swap(int* a,int* b); int main() { int a=5,b=6; swap(&a,&b); printf("a=%d b=%d",a,b); return 0;
2016-08-13 09:49:03 761
原创 LeetCode|Reverse Linked List
【问题描述】 Reverse a singly linked list. 【解答】 class Solution { public: ListNode* reverseList(ListNode* head) { if(head==NULL || head->next==NULL) return head; ListNode* pre=NULL;
2016-08-12 15:42:19 309
原创 LeetCode|Intersection of Two Linked Lists
【问题描述】 Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: A: a1 → a2 ↘
2016-08-12 09:42:10 321
原创 LeetCode|Merge Two Sorted Lists
【问题描述】 Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists. 【解答1】 特殊情况:若有一个链表为空,则返回另一个链表。 class Solution {
2016-08-11 22:51:00 402
原创 LeetCode|Remove Duplicates from Sorted List
【问题描述】 Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3. 【解答】 运用一个附加指针来记
2016-08-09 21:50:32 294
原创 LeetCode|Remove Nth Node From End of List
【问题描述】 Given a linked list, remove the nth node from the end of list and return its head. For example, Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the
2016-08-09 10:58:44 346
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人