
leetcode
看个人资料
毕业于哥伦比亚大学
展开
-
Min Stack
Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) – Push element x onto stack. pop() – Removes the element on top of the stack. top() – Get the原创 2016-11-28 19:07:13 · 160 阅读 · 0 评论 -
Add Strings
Given two non-negative numbers num1 and num2 represented as string, return the sum of num1 and num2. 编程答案:class Solution {public: string addStrings(string num1, string num2) { if(num1.siz原创 2016-11-28 21:31:34 · 148 阅读 · 0 评论 -
Sqrt(x)
struct ListNode{ int val; ListNode *next;};void printList(ListNode *head){ ListNode *p; p = head->next; while(p) { cout << p->val<<endl; p = p->next; }}原创 2016-12-01 17:24:33 · 400 阅读 · 0 评论 -
Power of Two
题目:Given an integer, write a function to determine if it is a power of two. 判断一个数是否是2的幂,如果是2的幂改善,这个数最高位是1,这个数减1,除最高位,其余都为零,利用这个特点,可以判断出是否是2的幂。class Solution {public: bool isPowerOfTwo(int n) {原创 2016-11-27 15:17:52 · 202 阅读 · 0 评论 -
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 you are given the third node with value原创 2016-11-27 16:04:39 · 206 阅读 · 0 评论 -
Rotate List
Given a list, rotate the list to the right by k places, where k is non-negative.For example: Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL. 题目要求:旋转链表,要主要k等于0及k大于链表长度的情况,可以通过取余就可以解决原创 2016-11-28 12:22:39 · 208 阅读 · 0 评论 -
Reverse Linked List
题目:Reverse a singly linked list. 将链表反向输出,遍历链表,先遍历的后输出,最后遍历的先输出,实际上是一个栈的过程,利用栈实现。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(in原创 2016-11-28 14:38:23 · 143 阅读 · 0 评论 -
Happy Number
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 integer, replace the number by the sum of the squares of i原创 2016-11-28 15:15:57 · 189 阅读 · 0 评论