![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
不折腾就闹心
这个作者很懒,什么都没留下…
展开
-
算法课 第四周 Find Bottom Left Tree Value
Given a binary tree, find the leftmost value in the last row of the tree.Example 1:Input: 2 / \ 1 3Output:1Example 2: Input: 1 / \ 2 3原创 2017-03-21 11:31:20 · 1023 阅读 · 0 评论 -
十三周 Dynamic programming counting bits
Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their binary representation and return them as an array.Example:For num = 5原创 2017-06-04 13:00:47 · 344 阅读 · 0 评论 -
算法课第五周 Gas Station
There are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from station i to it原创 2017-03-26 21:56:35 · 676 阅读 · 0 评论 -
证明题-算法概论8.3证明吝啬SAT问题
吝啬SAT问题:给定一组子句(每个子句都是其中文字的析取)和整数k,求一个最多有k个变量为true的满足赋值——如果该赋值存在。证明吝啬问题是NP-完全问题。解题思路 1.什么是SAT问题 假设我们有这样一组子句: (a⋃b⋃c)⋂(a⋃b¯)⋂(b⋃c¯)(a¯⋂c)⋂(a¯⋃b¯⋃c¯) 我们需要做的就是找到a,b,c的取值(true or false)使得该表达式的结果是true,假设原创 2017-07-01 18:41:07 · 775 阅读 · 0 评论 -
算法第七周 Arithmetic Slices
A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.For example, these are arithmetic sequence:1,原创 2017-04-09 19:57:52 · 620 阅读 · 0 评论 -
算法课第十八周Same Tree
Same TreeGiven two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the same value.解题思路: 给定两原创 2017-07-01 18:31:14 · 435 阅读 · 0 评论 -
算法课十七周 Single Number
Given an array of integers, every element appears twice except for one. Find that single one.Note: Your algorithm should have a linear runtime complexity. > Could you implement it without using extra原创 2017-06-23 16:19:51 · 402 阅读 · 0 评论 -
单链表的读取插入删除
1单链表的读取 声明一个指针P指向链表中的第一个结点,初始化j从1开始; 当jStatus GetElem(LinkList L, int i, ElemType *e){ LinkList p; p=L->next; int j=1; while(p && j<i){ p=p->next; ++j; } if(!p || j>i原创 2017-09-06 16:45:35 · 401 阅读 · 0 评论 -
简单选择排序
选择排序—简单选择排序(Simple Selection Sort) 基本思想:在要排序的一组数中,选出最小(或者最大)的一个数与第1个位置的数交换;然后在剩下的数当中再找最小(或者最大)的与第2个位置的数交换,依次类推,直到第n-1个元素(倒数第二个数)和第n个元素(最后一个数)比较为止。简单选择排序的示例:操作方法:第一趟,从n 个记录中找出关键码最小的记录与第一个记录交换;第二趟,从第二个记原创 2017-08-30 10:01:47 · 598 阅读 · 2 评论 -
cvte笔试题
输入:hello world 输出: world hello#include <stdio.h>#include <string.h>int main(){char s[3000],c[1000][20]={0};//c[j]来储存单词,k是单词中的字母int i,j=0,k=0;gets(s);for(i=0; i<strlen(s); i++){if(s[i]==' '){原创 2017-09-07 20:33:10 · 1149 阅读 · 0 评论 -
冒泡排序c++
交换排序—冒泡排序(Bubble Sort) 基本思想:在要排序的一组数中,对当前还未排好序的范围内的全部数,自上而下对相邻的两个数依次进行比较和调整,让较大的数往下沉,较小的往上冒。即:每当两相邻的数比较后发现它们的排序与排序要求相反时,就将它们互换。算法的实现:#include<iostream>#include<string>using namespace std;void print原创 2017-08-30 11:12:41 · 632 阅读 · 1 评论 -
十四周 dynamic programming Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at any原创 2017-06-04 15:36:53 · 391 阅读 · 0 评论 -
第十六周Dynamic Programing Ones and Zeroes
In the computer world, use restricted resource you have to generate maximum benefit is what we always want to pursue. For now, suppose you are a dominator of m 0s and n 1s respectively. On the other原创 2017-06-17 09:45:23 · 383 阅读 · 0 评论 -
算法课第三周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 than the node’s key. The right原创 2017-03-12 16:34:11 · 432 阅读 · 0 评论 -
算法课第六周 贪心算法
Given a collection of intervals, find the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.Note:You may assume the interval's end point is always bigger原创 2017-04-09 19:02:58 · 443 阅读 · 0 评论 -
算法第八周 Is Subsequence
Given a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) string, an原创 2017-04-17 09:52:20 · 482 阅读 · 0 评论 -
第九周 算法Integer Break
Given a positive integer n, break it into the sum of at least two positive integers and maximize the product of those integers. Return the maximum product you can get.For example, given n = 2, return 1原创 2017-04-23 20:16:09 · 364 阅读 · 0 评论 -
第十周 动态规划 Combination Sum IV
Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.Example:nums = [1, 2, 3]target = 4The possible com原创 2017-05-18 08:29:30 · 559 阅读 · 0 评论 -
十一周- Dynamic Programming- Coin Change
You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of money c原创 2017-05-18 08:35:09 · 557 阅读 · 0 评论 -
十二周动态规划 Longest Palindromic Subsequence
Given a string s, find the longest palindromic subsequence's length in s. You may assume that the maximum length of s is 1000.Example 1:Input:"bbbab"Output:4One possible longest palindromic subsequ原创 2017-05-18 08:38:44 · 425 阅读 · 0 评论 -
算法第二周
这周上课的内容主要是讲了分治算法 挑选的题目:在一个未排序的数组里面找到第K大的元素。Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example,Giv原创 2017-03-05 16:46:03 · 476 阅读 · 0 评论 -
算法课第一周
题目要求Given two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100"代码public class Solution { public String addBinary(String a, String b) { if(a=原创 2017-02-25 17:49:40 · 535 阅读 · 0 评论 -
十五周 Perfect Squares
Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) which sum to n.For example, given n = 12, return 3 because 12 = 4 + 4 + 4; given n = 13, return原创 2017-06-17 09:40:29 · 347 阅读 · 0 评论 -
交换排序—快速排序(Quick Sort)
基本思想:1)选择一个基准元素,通常选择第一个元素或者最后一个元素,2)通过一趟排序讲待排序的记录分割成独立的两部分,其中一部分记录的元素值均比基准元素值小。另一部分记录的 元素值比基准值大。3)此时基准元素在其排好序后的正确位置4)然后分别对这两部分记录用同样的方法继续进行排序,直到整个序列有序。快速排序是通常被认为在同数量级(O(nlog2n))的排序方法中平均性能最好的。但若初始序列按关键码有原创 2017-08-30 13:46:42 · 636 阅读 · 1 评论