Remove Linked List Elements [leetcode] Remove Linked List ElementsRemove all elements from a linked list of integers that have value val.Example Given: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6 Return: 1 –> 2 –> 3 –> 4 –> 5 题意: 删除给定的节点
Contains Duplicate [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
[leetcode](Add Binary C语言实现) Add Binary Given two binary strings, return their sum (also a binary string).For example, a = “11” b = “1” Return “100”. 题意:求两个二进制字符串相加,并把结果保存为二进制字符串。 解题思路:动态申请一个数组用于保存相加后的二进制字符串,两个二进制相加有两种可能: 1
[leetcode](Remove Duplicates from Sorted Array II C语言实现) Remove Duplicates from Sorted Array II Follow up for “Remove Duplicates”: What if duplicates are allowed at most twice?For example, Given sorted array A = [1,1,1,2,2,3],Your function should return
[leetcode](Remove Duplicates from Sorted List II C语言实现) Remove Duplicates from Sorted List II Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example, Given 1->2->3->3->4-
[百度2016实习 在线笔试 编程第一题 度度熊 C语言] 最粗暴的实现算法,没有考虑优化问题。#include<stdio.h>#include <string.h>int function(char *str);int main(){ int num,temp,i; char s[100][10002]; scanf("%d",&num); temp = num;i = 0; while(num--){
[leetcode](Gray Code 格雷码 C语言实现) Gray Code The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequen
[leetcode]Reverse Linked List II (反转链表值 C语言实现) 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
[leetcode]Validate Binary Search Tree (判断有效二叉搜索树 C语言实现) 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 t
[leetcode]Construct Binary Tree from Preorder and Inorder Traversal(根据前序、中序遍历确定一棵二叉树 C语言) Construct Binary Tree from Preorder and Inorder Traversal Given preorder and inorder traversal of a tree, construct the binary tree.Note: You may assume that duplicates do not exist in the tree. 题意:
[leetcode]Convert Sorted Array to Binary Search Tree (有序数组转化为二叉搜索树 C语言) Convert Sorted Array to Binary Search Tree Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 题意:给定一颗有序数组,求出二叉搜素树 解题思路:二叉搜索树满足的条件是:左子树<根节点<右子树 采用递归思路
[leetcode]Construct Binary Tree from Inorder and Postorder Traversal (利用中序遍历和后续遍历确定一颗二叉树) Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder traversal of a tree, construct the binary tree.Note: You may assume that duplicates do not exist in the tree.
读取一个字符串,输出它里面字符的所有组合 例如:abc,它的所有字符组合为a,b,c,ab,ac,bc,abc 对于这种类型的题,想到的第一思路就是采用递归进行求解。 首先我们申请一个与所求字符串一样大小的字符数组s,用于保存各个字符的组合。 对于abc这样字符串的进行递归实现: a,ab,abc,ac,b,bc,c 实现代码:#include <stdio.h>#include <string.h>int Recursion(
给定一个数N,要求列出所有不大于N的素数 对于素数的定义,可以参考百度百科,素数(质数),除了可以被本身及1整除以外,不会再被其他数整除。典型的素数例如,2 3 5 7 11 13 17 19 23 …… 最简单的方法就是遍历这个整数m,遍历它可能存在的所有除数,例如对于11(1,2,3,4,5,6,7,8,9,10,11)只有1和11能被整除,所以判断11为素数,而对于12(1,2,3,4,5,6,7,8,9,10,11,12)可以被(
[leetcode]Valid Sudoku(判断有效数独 C语言实现) Valid Sudoku Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’.A partially filled
[leetcode]Count and Say (伯爵说 C语言实现) Count and Say The count-and-say sequence is the sequence of integers beginning as follows: 1, 11, 21, 1211, 111221, …1 is read off as “one 1” or 11. 11 is read off as “two 1s” or 21. 21 is read of
[leetcode]Length of Last Word (求最后一个单词的长度 C语言实现) Length of Last Word Given a string s consists of upper/lower-case alphabets and empty space characters ’ ‘, return the length of last word in the string.If the last word does not exist, return 0.Note
[leetcode]Climbing Stairs(爬楼梯 C语言) Climbing Stairs You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? 题意:你去爬楼梯,需要爬n个台阶,你
[leetcode]Remove Duplicates from Sorted List (删除有序节点的值重复的节点 C语言) 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->
[leetcode]Merge Sorted Array (两个有序数组的合并 C语言实现) Merge Sorted Array Given two sorted integer arrays A and B, merge B into A as one sorted array.Note: You may assume that A has enough space (size that is greater or equal to m + n) to hold additiona