2018年2月28日
摘要: Find the sum of all left leaves in a given binary tree. 思路:在递归的时候访问左右节点记录一下,比如做节点标记1,右节点标2,那么当遍历到叶子节点的时候,我们只加标记为1的叶子节点的值。 阅读全文
posted @ 2018-02-28 19:39 Beserious 阅读(60) 评论(0) 推荐(0)
摘要: Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. For exa 阅读全文
posted @ 2018-02-28 19:34 Beserious 阅读(97) 评论(0) 推荐(0)
摘要: You are a product manager and currently leading a team to develop a new product. Unfortunately, the latest version of your product fails the quality c 阅读全文
posted @ 2018-02-28 19:33 Beserious 阅读(99) 评论(0) 推荐(0)
摘要: Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. 前缀和思想。如果修改的次数比较多,那么就可以用线段树了, class NumArray { pu 阅读全文
posted @ 2018-02-28 19:29 Beserious 阅读(91) 评论(0) 推荐(0)
摘要: Given an integer, write a function to determine if it is a power of three. 判断一个数,是不是3的n次幂。直接换底公式求解 阅读全文
posted @ 2018-02-28 19:22 Beserious 阅读(92) 评论(0) 推荐(0)
摘要: Given two arrays, write a function to compute their intersection. Example: Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2]. Note: Each eleme 阅读全文
posted @ 2018-02-28 19:07 Beserious 阅读(105) 评论(0) 推荐(0)
摘要: 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. 不用加减法进行求和运算。 阅读全文
posted @ 2018-02-28 19:03 Beserious 阅读(110) 评论(0) 推荐(0)
摘要: 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 y 阅读全文
posted @ 2018-02-28 18:25 Beserious 阅读(96) 评论(0) 推荐(0)
摘要: Given a positive integer num, write a function which returns True if num is a perfect square else False. Note: Do not use any built in library functio 阅读全文
posted @ 2018-02-28 18:23 Beserious 阅读(132) 评论(0) 推荐(0)
摘要: 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? 判断一个链表是不是回文的。 思路:遍历节点得到总数tot,然后反转 阅读全文
posted @ 2018-02-28 18:21 Beserious 阅读(114) 评论(0) 推荐(0)
摘要: Implement the following operations of a queue using stacks. push(x) Push element x to the back of queue. pop() Removes the element from in front of qu 阅读全文
posted @ 2018-02-28 18:16 Beserious 阅读(141) 评论(0) 推荐(0)
摘要: Implement the following operations of a stack using queues. push(x) Push element x onto stack. pop() Removes the element on top of the stack. top() Ge 阅读全文
posted @ 2018-02-28 18:14 Beserious 阅读(135) 评论(0) 推荐(0)
摘要: Reverse a singly linked list. 思路:递归,每次保存一下上一个节点用来构造反转后的链表。 非递归,需要多记录两个值. 阅读全文
posted @ 2018-02-28 18:09 Beserious 阅读(95) 评论(0) 推荐(0)
摘要: Given two strings s and t, determine if they are isomorphic. Two strings are isomorphic if the characters in s can be replaced to get t. All occurrenc 阅读全文
posted @ 2018-02-28 16:15 Beserious 阅读(114) 评论(0) 推荐(0)
摘要: Remove all elements from a linked list of integers that have value val. 思路:声明两指针,类似快慢指针,快指针遇到val时跳过,直到值不是val这时修改慢指针的next为快指针,慢指针移到快指针这个位置。 阅读全文
posted @ 2018-02-28 16:00 Beserious 阅读(88) 评论(0) 推荐(0)
摘要: You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping yo 阅读全文
posted @ 2018-02-28 15:15 Beserious 阅读(112) 评论(0) 推荐(0)
摘要: Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), retur 阅读全文
posted @ 2018-02-28 15:10 Beserious 阅读(88) 评论(0) 推荐(0)
摘要: Given a Binary Search Tree (BST) with the root node root, return the minimum difference between the values of any two different nodes in the tree. Not 阅读全文
posted @ 2018-02-28 15:08 Beserious 阅读(307) 评论(0) 推荐(0)
摘要: Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive intege 阅读全文
posted @ 2018-02-28 15:07 Beserious 阅读(119) 评论(0) 推荐(0)
摘要: 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 阅读全文
posted @ 2018-02-28 15:03 Beserious 阅读(123) 评论(0) 推荐(0)
摘要: We define a harmonious array is an array where the difference between its maximum value and its minimum value is exactly 1. Now, given an integer arra 阅读全文
posted @ 2018-02-28 14:54 Beserious 阅读(113) 评论(0) 推荐(0)
摘要: 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 阅读全文
posted @ 2018-02-28 14:49 Beserious 阅读(93) 评论(0) 推荐(0)
摘要: In a given integer array nums, there is always exactly one largest element. Find whether the largest element in the array is at least twice as much as 阅读全文
posted @ 2018-02-28 13:26 Beserious 阅读(116) 评论(0) 推荐(0)
摘要: Given a string S, check if the letters can be rearranged so that two characters that are adjacent to each other are not the same. If possible, output 阅读全文
posted @ 2018-02-28 13:21 Beserious 阅读(300) 评论(0) 推荐(0)