Day 1

Day 1

Hello friends. I am going to start to share my coding challenge on LinkedIn today. I started it 3 days before on my LeetCode and GitHub pages. But after a while, I decided to share it using LinkedIn to show more people and to give more information.


On the first day, I solved 3 problems on LeetCode. The list of problems is below:

  1. Problem 28. Find the first occurrence in the string. You can see my solution here as well.

/*
 * @param {string} haystack
 * @param {string} needle
 * @return {number}
 */
	

var strStr = function (haystack, needle) {
  // checks full string named needle exists in haystack
  if (haystack.includes(needle)) {
    // if it returns true we will get the firs occurance using 
    // .indexOf() method
    return haystack.indexOf(needle);
  } else {
	return -1;
  }
};        

2. Problem 58. Length of the last word. The solution is below.

/*
 * @param {string} s
 * @return {number}
 */
	
var lengthOfLastWord = function (s) {
  s = s.trim().split(" ");
  let lastWord = s[s.length - 1].length;
  return lastWord;
};        

3. Problem 67. Add Binary

  var addBinary = function (a, b) 
    let len1 = a.length,
      len2 = b.length,
      max = Math.max(len1, len2),
      res = "",
      carry = 0,
      val = 0;

    for (var i = 0; i < max; i++) {
      val = Number(a[len1 - 1 - i] || 0) + Number(b[len2 - 1 - i] || 0) + carry;
      carry = Math.floor(val / 2);
      res = (val % 2) + res;
    }
  
    if (carry) res = 1 + res;
  
    return res;
   }        

Thank you for your time investing in my post. If you find it useful, share it with your friends.


My repository for challenges:

My LeetCode profile:


#leetcode #coding #challenges #programming

Jaloliddin Yusupov

Full Stack Engineer at AIFU university

1 年

assalamu aleykum, juda ajoyib izlanishdan to'xtamang

回复

要查看或添加评论,请登录

Abbosbek Sulaymonov的更多文章

  • Hey, how long will this task take?

    Hey, how long will this task take?

    A PM walks up to a developer and asks, "Can you build this feature? When will it be done?" The developer pauses. If…

    2 条评论
  • Polyfills in JavaScript

    Polyfills in JavaScript

    Assalamu alaykum, everyone! I haven't been able to write anything for a long time. I hope you will forgive me for this.

  • Day - 100

    Day - 100

    Assalamu alaykum, everyone! And finally, today is the last day of my 100-day challenge. Getting to this day has not…

    2 条评论
  • Day - 99

    Day - 99

    Assalamu alaykum, everyone! How are you guys? It is the 99th day of my coding challenge! So, I am going to post a good…

    1 条评论
  • Day - 98

    Day - 98

    Assalamu alaykum, everyone! It is time to share the 98th day of my coding challenge! These days, I am solving problems…

  • Day - 97

    Day - 97

    Assalomu alaykum, everyone! It is the 97th day! I am glad to see you here! Today I am going to show a solution for…

    1 条评论
  • Day - 96

    Day - 96

    Assalamu alaykum, everyone! It is the 96th day of my coding challenge! We passed 96 days ). It is a great result! I…

  • Day - 95

    Day - 95

    Assalamu alaykum, everyone! Today, I am going to share the 95th day of my coding challenge! So, let's start the coding!…

  • Day - 94

    Day - 94

    Assalamu alaykum, everyone! It is the 94th day of my coding challenge! I do not know how to describe my thoughts! So…

  • Day - 93

    Day - 93

    Assalomu alaykum, everyone! I am glad to see you here! It is the 93rd day of my coding challenge! So, let's start the…

社区洞察

其他会员也浏览了