Giter Site home page Giter Site logo

leetcode's Issues

同行

你好,我之前找工作也是用的js刷的题,大概刷了240多题, 如果有需要我也可以submit我的一些code

很好的repo

对了,我最近也在静心研读underscore~~有机会可以交流交流
我的email:[email protected]

thx

3Sum.js

The javascript version is exceeding time limit for longer list.
Perhaps you may refer to following java code to develop a javascript version.

    public List<List<Integer>> threeSum(int[] nums) {
        
        List<Integer> list;
        List<List<Integer>> retList = new  LinkedList<>();
        Arrays.sort(nums);
        for( int i = 0; i < nums.length && nums[i] <= 0; i++){
            if( i > 0 && nums[i] == nums[i-1])
                continue;
            int sum = (-1)*nums[i], front = i + 1, behin = nums.length - 1;
            while( front < behin )
                if( nums[front] + nums[behin] > sum) 
                    behin--;
                else if( nums[front] + nums[behin] < sum) 
                    front++;
                else{
                    list = new LinkedList<Integer>();
                    list.add(nums[i]);
                    list.add(nums[front]);
                    list.add(nums[behin]);
                    retList.add(list);
                    while( front<behin && nums[front]==nums[front+1]) front++;
                    while( front<behin && nums[behin]==nums[behin-1]) behin--;
                    front++;
                    behin--;
                }
        }
        return retList;
    }

Valid Parenthesis

The golang solution using byte to validate the parenthesis hits 0ms compared to ~108ms in javascript.
Maybe we shall try to find a better solution.

func isValid(s string) bool {
	if len(s)%2 != 0 {
		return false
	}
	left := map[byte]struct{}{
		'(': struct{}{},
		'[': struct{}{},
		'{': struct{}{},
	}
	right := map[byte]struct{}{
		')': struct{}{},
		']': struct{}{},
		'}': struct{}{},
	}
	bytes := []byte(s)
	stack := []byte{}
	for i := range bytes {
		if _, ok := left[bytes[i]]; ok {
			stack = append(stack, bytes[i])
		} else if _, ok = right[bytes[i]]; ok {
			if len(stack) == 0 {
				return false
			}
			switch stack[len(stack)-1] {
			case '(':
				if bytes[i] != ')' {
					return false
				}
			case '[':
				if bytes[i] != ']' {
					return false
				}
			case '{':
				if bytes[i] != '}' {
					return false
				}
			}
			stack = stack[:len(stack)-1]
		} else {
			return false
		}
	}
	if len(stack) == 0 {
		return true
	}
	return false
}

关于readme.md的 update

你好,从博客园一路逛过来看的。感觉 leetcode 上能拿 js 刷了这么多题的人真不多见😂,我之前也是用 JS, 后来还是随大流用了 Java

主要想问下你 readme.md 是写了什么脚本更新吗?方便就此交流一下吗?
谢谢

Add Two Numbers这个算法有什么用啊?

看样子就是把链表的每一个数字加起来,如果超过10就取余数,进的一个1就参与到后面2个数的相加里去,最后得出一个新的链表,这样做的意义是什么?哪些实际问题是需要这种算法的?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.