![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C/C++
文章平均质量分 61
Jasonfang0118
这个作者很懒,什么都没留下…
展开
-
[Leetcode]Two Sum II - Input array is sorted
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two number原创 2016-12-27 14:52:39 · 498 阅读 · 0 评论 -
[Leetcode]Reverse Linked List-再写单链表反转
Leetcode碰巧又出现这个问题,看来面试算法这个是很常见的题型,不过很久没写过,这次写来又花了不少时间,主要耽搁在思想的选择上:一是想通过遍历时直接将指针反转,这样比较高效,但是需要处理好前后指针及后续的关系;二是通过构建一个新的链表头,然后遍历时直接将链表元素加入到新链接中,该算法比较简明;/** * Definition for singly-linked list.原创 2016-11-17 10:12:00 · 2033 阅读 · 0 评论 -
[Leetcode] Move Zeroes
Given an array nums, write a function to move all 0's to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling your fu原创 2016-11-16 16:42:49 · 292 阅读 · 0 评论 -
[Leetcode] Invert Binary Tree
Invert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1最先想到的当然是递归的思想,将两个左右指针进行互换:/** * Definition for a binary tree node.原创 2016-11-11 11:00:19 · 220 阅读 · 0 评论 -
[Leetcode]Find the Difference
Given two strings s and t which consist of only lowercase letters.String t is generated by random shuffling string s and then add one more letter at a random position.Find the letter that was原创 2016-11-10 16:21:52 · 274 阅读 · 0 评论 -
[Leetcode]Single Number
Given an array of integers, every element appears twice except for one. Find that single one.思路:1. 使用HASH表存储每个数组元素出现的次数2. 理解按位异或操作的本质原理int singleNumber(int* nums, int numsSize) { int原创 2016-11-10 14:06:24 · 215 阅读 · 0 评论 -
[Leetcode]Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.解:考虑深度优先访问方式求深度./** * Def原创 2016-11-10 13:59:50 · 230 阅读 · 0 评论 -
[LeetCode]Add Two Numbers解析
将两个链表的值进行相加,并返回一个新的链表,注意两个地方:一是考虑两个链表的长度是否相同,二是考虑相加后的进位问题/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* a原创 2016-08-19 14:12:05 · 665 阅读 · 0 评论 -
实现单链表的反转
单链表的反转实现很常见:#include #include #include #define NUM 9typedef struct LNode{ int data; struct LNode *next;}LNode, *LinkedList;LNode slinklist = {0, NULL};int initLinkl原创 2016-08-30 14:04:45 · 693 阅读 · 0 评论 -
function to count the number of "1" of one byte
function to count the number of "1" of one byte ,for example 5(0101)has two "1"经常遇到的面试题,毫无疑问需要借助位操作:unsigned int bitCount (unsigned int value) { unsigned int count = 0; while (value >原创 2016-08-30 14:02:14 · 299 阅读 · 0 评论 -
实现memove
void *memmoves(void *dest, const void *src, size_t count){ char *tmp_dst = NULL; const char *tmp_src = NULL; if (dest <= src) { tmp_dst = dest; tmp_src = src;原创 2016-08-30 13:54:13 · 367 阅读 · 0 评论 -
求一个数组中子数组中的和的最大值
遇到的面试题:int maxSumOfArray(int array[], int len){ int mark = 0, i , j; int result = array[0]; for(i = 0; i < len; i ++) { if (mark >= 0) { mark += array[i]; } else { mark = arra原创 2016-08-30 13:59:09 · 539 阅读 · 0 评论 -
[Leetcode]Valid Anagram
Given two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.从题目看来,得到要求:1. 长度原创 2016-11-17 13:31:32 · 371 阅读 · 0 评论 -
[Leetcode]Contains Duplicate
Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every element原创 2016-11-17 18:53:16 · 284 阅读 · 0 评论 -
[Leetcode] Power of Three
Given an integer, write a function to determine if it is a power of three.判断一个数是否为3的幂:一,除数法,最容易想到的方法:1. 首先是能够整除2. 整除到最后的数一定为1则说明TRUE否则FALSEbool isPowerOfThree(int n) { if (n <= 0)原创 2016-11-17 19:25:22 · 338 阅读 · 0 评论 -
[Leetcode] Number of 1 Bits & Counting Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11' has binary representation 000000原创 2016-11-19 15:27:46 · 353 阅读 · 0 评论 -
[Leetcode] Range Sum Query - Immutable
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRan原创 2016-11-28 14:28:37 · 405 阅读 · 0 评论 -
[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-11-28 11:29:52 · 415 阅读 · 0 评论 -
[Leetcode] Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.题意:查找字符串数组中的最长子串思路:1. 找到最短长度的字符串,然后求得其他字符串与最小串的最大公共长度char* longestCommonPrefix(char**strs, int strsSize) {原创 2016-11-23 19:10:57 · 347 阅读 · 0 评论 -
[Leetcode] Contains Duplicate II
Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j]and the difference between i and j is at most k.题原创 2016-11-23 16:16:55 · 324 阅读 · 0 评论 -
[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 end, the原创 2016-11-23 13:18:26 · 252 阅读 · 0 评论 -
[Leetcode] Remove Duplicates from Sorted Array
Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with原创 2016-11-22 13:03:47 · 270 阅读 · 0 评论 -
判断单链表是否有环
1、对于单链表而言,只有通过从头到尾的遍历方式,如果发现尾指针指向头指针则说明有环。2、使用双指针,一个遍历的速度快,一个较慢,如果快的指针追上了慢的那个说明有环:/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next;原创 2016-11-21 17:22:52 · 341 阅读 · 0 评论 -
[Leetcode] Remove Element
Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.原创 2016-11-21 16:41:36 · 262 阅读 · 0 评论 -
[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.思路:1. 前提是整个链表是有序的2.原创 2016-11-19 14:58:09 · 284 阅读 · 0 评论 -
[Leetcode] Best Time to Buy and Sell Stock
Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),原创 2016-11-18 10:20:09 · 327 阅读 · 0 评论 -
[Leetcode]字符串的反转
Write a function that takes a string as input and returns the string reversed.Example:Given s = "hello", return "olleh".很简单,针对长度为奇偶情况不同,作对应的处理:char* reverseString(char* rs) { char *p原创 2016-08-28 14:33:15 · 798 阅读 · 0 评论 -
[Leetcode]Longest Substring Without Repeating Characters
题为:求最大长度的子串,要求不能有重复字符首先想到的是暴力解决方法,循环创建每个子串,并记录长度,同时确认是否有重复字符,如下:int lengthOfLongestSubstring(char* s) { int maxLen = 0; int i = 0, j = 0, len = 0; char *p = s, *res = s; len = strlen(s);原创 2016-08-28 11:31:21 · 529 阅读 · 0 评论 -
将整数X的第p位开始的n个位(二进制位)取反并且将结果返回
今天笔试遇到的题,实现了一下://写一函数,将整型X的第p位开始的n个位(二进制位)取反,并且将结果返回#include stdio.h>#include math.h>#define Funa(a,b,c)\{\ a=a*b;\ c=a-b;\}void Funa2(int a,int b,int c){ a = a*b;原创 2014-05-07 17:21:45 · 4076 阅读 · 0 评论 -
双链表有关操作的实现
#include "stdio.h"#include "stdlib.h"#define OK 1#define ERROR 0/*---双向链表的存储结构---*/typedef int ElemType;typedef int State;typedef struct DuLNode{ ElemType data; struct DuLNode *pri原创 2014-05-07 17:21:27 · 793 阅读 · 0 评论 -
Pro_2_win_countTest
BOOL isinteger(TCHAR *str){ //判断输入是否为整数 TCHAR strtmp[256]; int str_int = atoi(str); wsprintf(strtmp,"%i",str_int); if (!strcmp(strtmp,str)) { return TRUE; } else { return FALSE; }}//各个按钮事件void原创 2014-05-07 17:21:16 · 584 阅读 · 0 评论 -
typedef和define的详细区别
typedef是C语言语句,其功能是用户为已有数据类型取“别名”。 例如: typedef int INTEGER; 这以后就可用INTEGER来代替int作整型变量的类型说明了,如: INTEGER a,b; 用typedef定义数组、指针、结构等类型将带来很大的方便,不仅使程序书写简单而且使意义更为明确,因而增强了可读性。例如: typedef int a[10]; 表示a是整型数组类型,数组原创 2014-05-07 17:21:49 · 605 阅读 · 0 评论 -
栈内存与堆内存的区别
一:程序的内存分配 栈区(stack)有编译器自动分配释放,存放函数的参数,局部变量等. 堆区(heap)一般由程序员分配和释放,否则就由OS回收。堆用于存放全局变量,静态变量,常量字符串和函数代码(函数体的二进制代码).二:申请后系统的响应 栈:只要栈的剩余空间大于所申请的空间,系统将为程序提供内存,否则将报异常提示栈溢出。 堆:在记录空闲原创 2014-05-07 17:21:40 · 726 阅读 · 0 评论 -
今天面试遇到的题
#include stdio.h>int squar(volatile int *p){ return *p * *p;}int main(){ /* int a[]={1,2,11,4}; int *p; p = a; p+=2; printf("%d\n",*p);*/ unsigned int原创 2014-05-07 17:21:36 · 457 阅读 · 0 评论 -
volatile的作用
一个定义为volatile的变量是说这变量可能会被意想不到地改变,这样,编译器就不会去假设这个变量的值了。精确地说就是,优化器在用到这个变量时必须每次都小心地重新读取这个变量的值,而不是使用保存在寄存器里的备份。下面是volatile变量的几个例子: 1). 并行设备的硬件寄存器(如:状态寄存器) 2). 一个中断服务子程序中会访问到的非自动变量(Non-automatic var原创 2014-05-07 17:21:34 · 409 阅读 · 0 评论 -
单链表相关操作
#include "stdio.h"#include "stdlib.h"#define OK 1#define ERROR 0typedef ElemType int;typedef struct LNode{ ElemType data; //数据域 struct LNode *next; //指针域}LNode;typedef LNode原创 2014-05-07 17:21:24 · 470 阅读 · 0 评论 -
C中的access函数
int access(const char *filename, int amode); amode参数为0时表示检查文件的存在性,如果文件存在,返回0,不存在,返回-1。 这个函数还可以检查其它文件属性: 06 检查读写权限 04 检查读权限 02 检查写权限 01 检查执行权限 00 检查文件的存在性而这个就算这个文件没有读权限,也可原创 2014-05-07 17:22:37 · 527 阅读 · 0 评论 -
又遇到的一些
#include stdio.h>#include stddef.h>int main(){ /* unsigned int u; int k = -1; if(u>k){ printf(">-1\n"); } else if(u == k) { printf("=-1\n")原创 2014-05-07 17:21:38 · 544 阅读 · 0 评论 -
常量指针与指针常量
首先,我告诉大家一个小规则,就是像这样连着的两个词,前面的一个通常是修饰部分,中心词是后面一个词,怎么说呢。就像这里的常量指针和指针常量。 常量指针,表述为“是常量的指针”,它首先应该是一个指针。 指针常量,表述为“是指针的常量”,它首先应该是一个常量。 我再分开细细说明,常量指针,它是一个指针,什么样的指针呢?它是一个指向常量的指针,就是说我们定义了一个常量,比如 const int原创 2014-05-07 17:21:29 · 381 阅读 · 0 评论 -
记录的查增删(模拟)_ComboBox
static int count_list=0; //定义全局变量,记录添加的记录个数;void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify){ switch(id) { case IDC_ADD://增加记录功能; { HWND hwndcomb1原创 2014-05-07 17:21:20 · 524 阅读 · 0 评论