![](https://img-blog.csdnimg.cn/20201014180756919.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
chenpkai
爱编程,爱音乐
展开
-
28. Implement strStr()
Implement strStr().Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack实现strStr()函数:返回模式P在文本T中的索引,如果没有发现则返回-1。Brute Force:(暴力求解法)int原创 2016-08-30 10:15:41 · 376 阅读 · 0 评论 -
371. Sum of Two Integers
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.Example:Given a = 1 and b = 2, return 3.下面是我的实现int getSum(int a, int b) { int sum,carry=0;原创 2016-08-26 17:26:33 · 424 阅读 · 0 评论 -
104. 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.求二叉树的最大深度。最大深度是根节点到最远叶子节点路径上经过原创 2016-08-30 10:29:51 · 334 阅读 · 0 评论 -
231. Power of Two
Given an integer, write a function to determine if it is a power(乘幂) of two.判断一个整型数据是不是2的乘幂。2的乘幂的特点是二进制表示中只有一个1,比如4(0100),利用这个特点将该数减1(0011)再与自身(0100)相与结果应该是0,而非2乘幂则不具备该特性。bool isPowerOfTwo原创 2016-08-30 10:42:01 · 317 阅读 · 0 评论 -
169.Majority Element
Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element原创 2016-08-30 10:48:47 · 435 阅读 · 0 评论 -
234. Palindrome Linked List
Given a singly linked list, determine if it is a palindrome.给定单链表,判断链表数据是否为回文。Follow up:Could you do it in O(n) time and O(1) space?能否以O(n)的时间复杂度和O(1)空间复杂度实现?首先尝试较为简单的实现——不考虑空间复杂原创 2016-08-31 16:19:07 · 280 阅读 · 0 评论 -
237. Delete Node in a Linked List
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.写一个单链表中用于删除节点(除了尾节点)的函数,只提供待删除节点的入口。Supposed the linked list is 1 -> 2 -> 3 -> 4 and原创 2016-09-01 17:06:58 · 277 阅读 · 0 评论 -
206. Reverse Linked List
Reverse a singly linked list.逆置单链表。Hint:提示:A linked list can be reversed either iteratively or recursively. Could you implement both?单链表可以通过迭代或者递归来实现,你能都实现他们吗?先用迭代的方式实现:从第二原创 2016-09-01 21:38:24 · 303 阅读 · 0 评论 -
203. Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.删除整数链表中所有值为val 的元素ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --原创 2016-09-02 21:33:57 · 230 阅读 · 0 评论